Thanks Gil. I think i know the difference of "\w+" and "\w*" now.
Gil Magno 写道:
2018-07-17 19:56:59 +0800 Lauren C.:Hello, I want to match: /path/ /path/123 /path/abc but /path/?xxx should not be matched. This works: $ perl -le '$x="/path/abc"; print 1 if $x=~m{path/\w+}' 1 this works too: $ perl -le '$x="/path/?abc"; print 1 if $x=~m{path/\w+}' But it doesn't work for this case: $ perl -le '$x="/path/"; print 1 if $x=~m{path/\w+}'From "perlintro": Quantifier * : zero or more of the previous thing. Quantifier + : one or more of the previous thing. So "/path/" won't match m{path/\w+} because this regex wants "one or more \w" at that position, which the string doesn't have. If you use m{path/\w*} (note the asterisk) then you're saying "zero or more \w" at that position, and it'll match.it expects 1 returned. Can you help? thanks. -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
-- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] http://learn.perl.org/
