Phoenix.pm: Regex question

Doug Miles doug.miles at bpxinternet.com
Wed Feb 7 14:43:27 CST 2001


Thomas Whitney wrote:
> 
> OK, this is my best guess. Quite the hack, and I am sure I missed
> something, but I have spent way too much time on it ;)
> 
> my $string = 'DailyNAV "Print STDERR \"$c\"" nav 1 2 3';
> my @list = map {($x=$_)=~s/\\"/"/g?$x:$x?$x:()} $string =~
> /"((?:\\"|.)*?)"|(\S+)/g;
> 
> print "$string\n";
> print ((join ',', at list),"\n");
> 
> BTW: I probably should have introduced myself as a new poster :)

I'll have to spend a couple of minutes on this one. :) Thanks!

> 
> Doug Miles wrote:
> 
> > 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!

-- 
- Doug

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



More information about the Phoenix-pm mailing list