Phoenix.pm: Regex question

Thomas Whitney whitneyt at agcs.com
Wed Feb 7 12:50:40 CST 2001


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 :)

Thanks
Tom

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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/phoenix-pm/attachments/20010207/b75d0624/attachment.htm


More information about the Phoenix-pm mailing list