[thelist] Regexs and headaches

Struan Donald struan at exo.org.uk
Thu Feb 9 06:57:43 CST 2006

* at 09/02 12:28 -0000 Dan Parry said:
> Hi all
> I have a regex problem that is giving me major hassles. the preamble is that
> the expression looks for opening HTML tags in a textarea value
> I've successfully got it to locate all opening tags and ignore self-closers
> (eg <br/>). it even picks up tags with attributes
> But (and this is a big but) it can't find single letter tags (eg <b>). it
> can find single letter tags with attributes though (eg <a
> href="http://example.org <http://example.org/> ">)
> Here is the regex:

your problem is that it has to match at least two characters:
> /\<[^\/]([^<>]*)[^\/]>/g
       ^            ^

I think, and I've not tested this, if you make the second [^\/]
optional thus: [^\/]? then is should work.

however, that won't capture the b as that'll be matched by the first
[^\/] so I suspect it still won't do what you want and what you
actually want is:


again, not tested and I'm just guessing what it is you want so I
could be wrong on that front.



More information about the thelist mailing list