in reply to Regex to match between [ref] and [/ref]

.* is greedy, you should use .*? also, you should use s///s so . matches newlines

Death to Dot Star!

  • Comment on Re: Regex to match between [ref] and [/ref]

Replies are listed 'Best First'.
Re^2: Regex to match between [ref] and [/ref]
by ultranerds (Hermit) on Jul 17, 2009 at 10:43 UTC
    Thanks - this seems to work perfectly :)

    $message =~ s{\[ref\](.*?)\[/ref\]}{add_sup_note2($1)}ge;

    Cheers

    Andy
Re^2: Regex to match between [ref] and [/ref]
by ultranerds (Hermit) on Jul 17, 2009 at 13:00 UTC
    Hi,

    Another question :)

    I'm now trying:

        $message =~ s{\[(ref|note|réf)\](.*?)\[/(ref|note|réf)\]}{add_sup_note2($2)}ge;

    ...so it will work with:

    [ref]something[/ref] [note]something[/note] [réf]something[/réf]


    ..but this one refuses to work :/

    [réf]something[/réf]

    Any ideas?

    TIA

    Andy
      Duh, nevermind - got it working. When I was testing, I had

      [réf]something[réf]

      ..instead of:

      [réf]something[/réf]

      Doh!