Hi guys,
I’m a bit stumped on a regular expression problem.
I want to match a “less than” symbol but not tag brackets in a string.
I’m assuming what I want to look for is a < which isn’t followed by a > in the rest of the string.
Any ideas how to write that as a regex?
Many thanks!
7stud
2
You could remove all the pairs:
/<[^>]*>/
and replace them with “”, and then search for the singletons.
Thanks a lot for that. Is there a way I could put the tags back in afterwards?
I’m basically validating a string to make sure all less than /more than symbols are HTML formatted, and want to leave the tags intact.
Nice one
I think this works …
/<(?=[^>]*<)/g
“<b> < lorem < </b>” to “<b> < lorem < </b>”
Man Regex is a double hard b*stard!
7stud
5
Thanks a lot for that. Is there a way I could put the tags back in afterwards?
Uhmm…do the replace on a copy of the original?