in reply to Regex Report

Sounds interesting, and though I cannot ATM think of any situation where I might want to use it, I am almost certain that I have in the past wished for something similar (if not the same). I am not sure if you meant for the last example:
# parses text like: # name = japhy age = "22" lang = 'Perl' # into a hash... but doesn't capture the quotes! my %data = $text =~ m{ ([^=\s]+) \s* = \s* (?: (?3= ['"] ) (.*? ) \3 | ( \S+ ) ) }xg;
So that what was previously in the (?2= .* ) would be returned.

This case might be resolved in other ways,
Sorry couldn't help presenting one:
while ( <DATA> ) { my %data = $_ =~ m{ ([^=\s]+) \s* = \s* ["']?( (?<=')[^']* | (?<=")[^"]* | \S+ )["']? }xg;

-enlil

(as a side note I would have to agree with demerphq that named captures would be cool as well)

Replies are listed 'Best First'.
Re^2: Regex Report
by japhy (Canon) on Jun 28, 2004 at 03:40 UTC
    I would make your example a little safer:
    my %data = $_ =~ m{ ([^=\s]+) \s* = \s* ["']? ( (?<= ' ) [^']* (?= ' ) | (?<= " ) [^"]* (?= " ) | (?<!['"]) \S+ (?! ['"] ) )["']? }xg;
    That, to me, seems safer, because it ensures a string that starts quoted ends quoted, and a string that doesn't start quoted doesn't end quoted (for some bizarre reason).
    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;