in reply to Regex priorities.

Does this match your expectations?

$s = '<COMMA>pre-stuff<EXHIBITING>some stuff</EXHIBITING>post-stuff</C +OMMA>';; print "$1 :: $2" while $s =~ s[<(\D+)>([^<]*?)</\1>][]gi;; EXHIBITING :: some stuff COMMA :: pre-stuffpost-stuff

Of course, it fails horribly if your non-tag content contains '<':

$s = '<COMMA>pre-stuff<EXHIBITING>some <= stuff</EXHIBITING>post-stuff +</COMMA>';; print "$1 :: $2" while $s =~ s[<(\D+)>([^<]*?)</\1>][]gi;; {zilch here}

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: Regex priorities.
by Steve_BZ (Chaplain) on May 28, 2012 at 15:01 UTC

    Hi BrowserUk,

    Thanks for that. It worked perfectly. I decided to change "<" for "/" because I use it less, in fact I do use "<" for other reasons, but not "/", so I ended up with:

    my $r = q( <(\D+)> # Opening tag <....> ([^/]*?) # stuff in the middle which does not h +ave the closing tab character '/' (<\/\1>) # closing tag of same type as opening +tag </....>. ); while ($text =~ m/$r/gix){ ... processing ... }

    Thanks for your help.

    Regards

    Steve