I'm trying to make a regex to get the first word in a < ... >
tag. I already have one to get all the words in a tag. I'm using this for it:
/<(.*?)>/
My question is, can I get the first word in a tag using a regex?
I'm trying to make a regex to get the first word in a < ... >
tag. I already have one to get all the words in a tag. I'm using this for it:
/<(.*?)>/
My question is, can I get the first word in a tag using a regex?
Here's a working solution: /<([^>\s]+)[^>]*>/
This will do it...
/<(.*?)\s/
In simple case /<(\S+)/
might be what you are looking for, or you might be more formal and actually list only characters allowed in tag names.
var tag = "< hello world>";
var regex = /<\s*(\S*)\b/;
if (match_arr = tag.match(regex)) {
alert("yes:" + match_arr[1]);
}
is there any way to get every word after the first word in a tag?
var tag = "< hello world goodbye >";
var regex = /<(.*?)>/;
if (match_arr = tag.match(regex)) {
var str = match_arr[1].trim();
var words = str.split(" ");
console.log("-->" + words.slice(1).join(" ") + "<--");
}
--output:--
-->world goodbye<--