in reply to Re^7: regex find and replace with a twist
in thread regex find and replace with a twist
BTW: The method used here fails in the following cases:
(Again, this assumes that we can, to begin with, even arrive at a common understanding of what is required. :)c:\@Work\Perl\monks>perl -wMstrict -le "for my $word (qw(XYZ$-.%abc&/ $-.%abc&/XYZ $-.%abc&/XYZ+=*)) { my @group1 = ( $word =~ m/(?: ([^a-zA-Z]+) ([a-zA-Z]+) )+ ([^a-zA-Z]+) /x ); my @group2 = map { $_ =~ /[a-zA-Z]/ ? split( //, $_ ) : $_ } @group1; my $new_word = join ( '', map { qq{[$_]} } @group2 ); print qq{'$word' -> '$new_word'}; } " 'XYZ$-.%abc&/' -> '[$-.%][a][b][c][&/]' '$-.%abc&/XYZ' -> '[$-.%][a][b][c][&/]' '$-.%abc&/XYZ+=*' -> '[&/][X][Y][Z][+=*]'
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: regex find and replace with a twist
by talexb (Chancellor) on Jul 19, 2018 at 13:58 UTC |