in reply to Help perlifying this string parse-o-rama
#!/usr/bin/perl use warnings; use strict; my $string = 'firstfield second field KNOWNWORD alwaysOneWord then one + or more make the last field'; my (@fields) = $string =~ / ^ (\S+) [ ] (.*?) [ ] KNOWNWORD [ ] (\S+) +[ ] (.*) /x; for my $i (0 .. $#fields) { print "$i:$fields[$i]\n"; }
Note that it might not work if KNOWNWORD is one of the words in the second field.
|
|---|