in reply to Abritrary multiple spaces as delimiter
This will work *if* you can guarentee that each of your two variable length fields will only contain single spaces?
my $s = '122 Genesis Chamber Mark Tedin + A U'; print join '|', $s =~ m[^(\S+)\s+\b(.*)\b\s{2,}\b(.*)\b\s{2,}(\S)\s+(\ +S)$]; 122|Genesis Chamber|Mark Tedin|A|U
m[^ # With the $, match the whole line (\S+) # The first field contains no spaces \s+ # and is separated from the next by at least 1 \b(.*)\b # 2nd field starts/stops on a word boundary # it can contain anything, \s{2,} # but only single concecutive spaces. \b(.*)\b # 3rd field is similarly defined \s{2,} # Again, 2 or more spaces defined the end of field (\S) # 4th Single non-space char \s+ # 1 or more spaces (\S) # 5th Single char. $]x
|
|---|