in reply to Regex not quite working- [b] tags

grab all the contents between b and /b

If I had correctly understood the idea, this is

/ \[b\] # match a [b] .*? # match anything (non greedy) \[\/b\] # match the next [/b] /xg

maybe a problem with the greedy nature of your regex?

Replies are listed 'Best First'.
Re^2: Regex not quite working- [b] tags
by ultranerds (Hermit) on Sep 20, 2011 at 12:26 UTC
    Thanks guys, I tried something like this before, but I must have been missing the ? ... doh!

    while ($post_message =~ /\[b\](.+?)\[\/b\]/sg) { print "BOLD: $1 \n\n"; $bold_length += length($1); }
    Working like a charm now - thanks!

    Andy