pike has asked for the wisdom of the Perl Monks concerning the following question:
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...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex capturing problem
by erikharrison (Deacon) on Mar 21, 2002 at 13:33 UTC | |
by demerphq (Chancellor) on Mar 21, 2002 at 15:16 UTC | |
Re: regex capturing problem
by larryk (Friar) on Mar 21, 2002 at 13:43 UTC | |
by pike (Monk) on Mar 21, 2002 at 14:12 UTC | |
by larryk (Friar) on Mar 21, 2002 at 16:23 UTC | |
by petral (Curate) on Mar 21, 2002 at 21:11 UTC | |
Re: regex capturing problem
by AidanLee (Chaplain) on Mar 21, 2002 at 13:51 UTC | |
Re: regex capturing problem
by stephane (Monk) on Mar 21, 2002 at 13:41 UTC |