#!/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.
In reply to Re: Help perlifying this string parse-o-rama
by choroba
in thread Help perlifying this string parse-o-rama
by balt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |