in reply to Reversing Arabic String direction
Here is a very crude, brute-force approach. I've no doubt that one of the regex masters here can do it much more efficiently.
use strict; use warnings; # I have no idea how unicode might affect this my $wrongway = 'This is a string with numbers 12345 that must be rever +sed without reversing the numbers.'; my @tmp; my @raw = split('',$wrongway); my @numeric; my $was_numeric = 0; for ( @raw ) { if ( /\d/ ) { push( @numeric, $_ ); $was_numeric = 1; next; } elsif ( $was_numeric ) { unshift( @tmp, @numeric ); $was_numeric = 0; @numeric = (); } unshift( @tmp, $_ ); } my $right_way =join('', @tmp); print "$wrongway\n"; print $right_way; print "\n\n";
Again, this is very ugly but might point the way to how to approach the problem.
|
|---|