in reply to Re: regex to collect local links in Markdown
in thread regex to collect local links in Markdown

Hi, am I missing something? I actually tried that earlier, and I get

Perl Monk
Regular Expressions
Perl Monks](http://www.perlmonks.org). This is what I look like ![mymugshot
--

when small people start casting long shadows, it is time to go to bed
  • Comment on Re^2: regex to collect local links in Markdown

Replies are listed 'Best First'.
Re^3: regex to collect local links in Markdown
by GrandFather (Saint) on Oct 27, 2007 at 19:53 UTC

    Note that the final assertion has changed from (?! \( ) to (?! \]\( ).


    Perl is environmentally friendly - it saves trees
      my $text = "Hello, I am a [Perl Monk], still not good at [Regular Expr +essions]. I have been helped immensely by the good monks at [Perl Mon +ks](http://www.perlmonks.org). This is what I look like ![mymugshot]. + Thank you."; listlink($text); sub listlink { my ($text) = @_; my @links = ( $text =~ / (?<!\!\[) # make sure the match is not preceded by a ![ (?<=\[) # but is in fact preceded by just a [ .*? # the match (?=\]) # followed by a ] (?!\]\() # but not followed by a ( /xg ); foreach my $link (@links) { print "$link\n"; } } ####### Perl Monk Regular Expressions Perl Monks](http://www.perlmonks.org). This is what I look like ![mymu +gshot

      Update: took out superfluous code.

      --

      when small people start casting long shadows, it is time to go to bed

        'twas the line breaks made the difference. The fix is to use [^\]]* for the match.

        (. doesn't match new line characters unless you ask nicely with the /s switch.)


        Perl is environmentally friendly - it saves trees