"be consistent" | |
PerlMonks |
regex capturing problemby pike (Monk) |
on Mar 21, 2002 at 13:17 UTC ( [id://153307]=perlquestion: print w/replies, xml ) | Need Help?? |
pike has asked for the wisdom of the Perl Monks concerning the following question:
I thought I understood regexes, but here is one I just can't figure out.
I wanted to break words at single quotes, so my idea was to use @words = $word =~ /^(\w+')([\w-]+)$/ Works fine. Then I discovered that sometimes there are words with more than one ' in them, so I changed it to @words = $word =~ /^(\w+')+([\w-]+)$/ inserted a + after the first group. I'd expect this to break e.g. "d'aujourd'hui" into "d':aujourd':hui", but what it does is it gives only the last two parts: "aujourd':hui". Why?!? pike P.S. I know I could use split to get what I want: @words = split /(?<=')(?!s$)/, $word but I'd just like to know whats wrong with my regex...
Back to
Seekers of Perl Wisdom
|
|