Phoenix.pm: Regex question

Doug Miles doug.miles at bpxinternet.com
Mon Feb 5 14:06:07 CST 2001


Thomas Whitney wrote:
> 
> How about?
> 
> my @list = $string =~ /(".*?"|\S+)/g;

I was trying to avoid getting the quotes back also.

> I think it is faster without the non greedy though?
> 
> What is happening with /"([^"]+)"/g; How does this work?

That globaly matches any sequence of a quote followed by one or more
non-quotes followed by a quote.

> What about with escapes?
> 
> my $string = 'DailyNAV "Print \"C\"" nav';
> 
> my @list = $string =~ /("(?:\\"|.)*?"|\S+)/g;

I might do this in the future, but I was trying to come up with a
non-complicated test case. :)

> 
> Michael Dearman wrote:
> 
> > Love a good regex mystery. This one still just that.
> >
> > Using the no-paren-mem operater  with your last regex appears to do away with the nulls.
> > my @tokens = $string =~ /"(?:[^"]+)"|(?:\S+)/g;
> >
> > Why? *shrug*
> > Mike D.

-- 
- Doug

Encrypted with ROT-26 - all attempts to decrypt are illegal under the
DMCA!



More information about the Phoenix-pm mailing list