I’m trying to get select just the string “Target” case-sensitive without grabbing any extra space before or after in HTML code, and not getting tags or tag attributes.
I have this regex:
/(?![^<>]*>) *(Target) *([^ \d])/g
This does grab multiple occurences of :Target, but it also grabs extra spaces before and after, the first character that follows it or extra whitespace after it.
In<div id="Target">text Target othertext</div> it grabs Target o
How do I perfect this?
Depending on what you’re using to handle the RegEx, it could be because you’re using multiple capture groups. I’d change the other capture groups to non-capturing by prefixing them with
?::EDIT:
With the additional information from the comments, shouldn’t this work?
EDIT #2:
Here’s a pass that starts with your original regex and uses some information from this StackOverflow post:
I’ve tested it myself and it seems to do what you need…or at least get you further along.