Skip to content

Instantly share code, notes, and snippets.

@jrcarl624
Last active November 17, 2021 18:06
Show Gist options
  • Save jrcarl624/70fe81cbc0a43dbc7f02d89f009d99a2 to your computer and use it in GitHub Desktop.
Save jrcarl624/70fe81cbc0a43dbc7f02d89f009d99a2 to your computer and use it in GitHub Desktop.
stuff
// regex to fine stuff in between html tags that are in a string and return the text in the html tag and place comma after each
// regex to find the text in between html tags and return the text in the html tag and place comma after each
var str = "<h1>Hello</h1><p>This is a paragraph</p>";
function findTextInBetweenTags(string) {
var regex = /<[^>]*>/g,
result = string.split(regex),
text = "",
array = [];
for (var i = 0; i < result.length; i++) {
if (result[i] != "") {
text += result[i] + ", ";
}
}
return text;
}
console.log(findTextInBetweenTags(str));
const regex = /<[^>]*>/g;
var str = "<h1>Hello</h1>, <p>This is a paragraph</p>";
function find(str, regex) {
let result = [];
let match;
while ((match = regex.exec(str)) !== null) {
result.push(match[1]);
}
return result;
}
console.log(find(str, regex));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment