in reply to Pattern with split
Output:my $pattern = qr/ (?: # Match beginning of line or whitespace sep +arator, no capture \A | \s+ ) ( # Capture one of: "[^"]*" # Matched double quotes | '[^']*' # Matched single quotes | {[^}]*} # Matched curly brackets | \S+? # non whitespace ) (?= # Match end of line or whitespace separator, + positive lookahead,no capture. \z | \s+ ) /x; my $data = '#VER "" 3 19950101 "Overforing BG till PG" 19950608'; my @values = $data =~ /$pattern/g; for my $i (0..$#values) { printf "%2d) %s\n",$i,$values[$i]; }
For complex regular expressions like this I would recommend using the 'x' modifier as in the example above. It makes maintenance easier.0) #VER 1) "" 2) 3 3) 19950101 4) "Overforing BG till PG" 5) 19950608
|
|---|