in reply to Can't quite get this regex working

You could either use  /\Q[[$tag_name]]\E((.|\n)*?)\[/) or add a modifier to the regex so that '.' matches '\n' as well, I think it was m or s

Replies are listed 'Best First'.
Re^2: Can't quite get this regex working
by GrandFather (Saint) on Apr 08, 2011 at 11:30 UTC

    Generally where you are matching up to some expected character a negated character set is better than .*?. In this case ([^\[]*) would be appropriate.

    True laziness is hard work
      Careful, when the delimiters are doubled, the file format might allow a single ] or [ on the inside, in which case the negated char class doesn't work.

      In that case you can use

      (?s:(?!\]\]).)*
        I much prefer:
        /[^]]*(?:][^]]+)*/
        which doesn't require any lookahead, backtracking or modifiers.
      Thanks, very good point - I'll have a play with that :)

      Cheers

      Andy
Re^2: Can't quite get this regex working
by ultranerds (Hermit) on Apr 08, 2011 at 11:20 UTC
    You legend - works like a charm!

    Thanks!

    Andy