in reply to Re: Can't quite get this regex working
in thread Can't quite get this regex working

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

Replies are listed 'Best First'.
Re^3: Can't quite get this regex working
by moritz (Cardinal) on Apr 08, 2011 at 11:41 UTC
    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.
Re^3: Can't quite get this regex working
by ultranerds (Hermit) on Apr 08, 2011 at 11:37 UTC
    Thanks, very good point - I'll have a play with that :)

    Cheers

    Andy