in reply to Re: help with lazy matching
in thread help with lazy matching

++ on this comment, except that I don't think you need to escape the slash inside the negated character class. You can just write [^/] .

Also (for the original post), you can leave out the '$_ =~' from your if statement if you want. Since there is no explicit variable in your while loop test, the if statement will match $_ by default.

--Nick

Replies are listed 'Best First'.
Re^3: help with lazy matching
by AnomalousMonk (Archbishop) on Jan 05, 2015 at 23:09 UTC

    You need to escape the forward-slash only if this character is used as the regex delimiter character.

    c:\@Work\Perl\monks>perl -wMstrict -le "$_ = '/foo/bar/baz/bat'; print qq{'$1'} if /([^/]+)$/; " Unmatched [ in regex; marked by <-- HERE in m/([ <-- HERE ^/ at ... c:\@Work\Perl\monks>perl -wMstrict -le "$_ = '/foo/bar/baz/bat'; print qq{'$1'} if m{([^/]+)$}; " 'bat'


    Give a man a fish:  <%-(-(-(-<