in reply to Split String after nth occurrence of a charater
It sort of depends on what your string looks like, but here is one solution:
my $string = "one two three four five six seven eight nine ten eleven +twelve thirteen"; my( $left, $right ); if( ( $left, $right ) = $string =~ m{\A((?:\S+\s){11})(.+)\z} ) { say "Left: ($left)"; say "Right: ($right)"; }
Output:
Left: (one two three four five six seven eight nine ten eleven ) Right: (twelve thirteen)
If you want to gobble that eleventh space, this will do it:
m{\A((?:(\S+\s){10}\S+)\s(.+)\z}
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Split String after nth occurrence of a charater
by Amiru (Initiate) on Nov 08, 2011 at 11:39 UTC | |
|
Re^2: Split String after nth occurrence of a charater
by JavaFan (Canon) on Nov 08, 2011 at 07:33 UTC |