returns all html <tag> matches in a document, How would i change it to include a negated character ^/ to skip the closing tags?
You want to find all <...> but ignore the </...>, correct?
Thats correct mate!
I assume all the tags start with a lower case Latin letter. In that case, this should work /<[a-z]*>/g
Yes this is definately a way around, But i was hoping to learn how to add a negative condition using ^ in the existing expression to exclude tags with / character. Please let me know, I'm sure someone knows.
Btw, following this advice, While searching for matches using js's match() this one works better : /<[a-z].*?>/g To help, lets say for input: "<h1>winter is coming</h1><tag>You know nothing, jon snow</tag>", /<[a-z]*>/g would return [ '<tag>' ]. While /<[a-z].*?>/g would return both: [ '<h1>', '<tag>' ]. Check it out!
Обсуждают сегодня