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:

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][+=*]'
(Again, this assumes that we can, to begin with, even arrive at a common understanding of what is required. :)


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

    Yup -- I agree 100%. As I was writing the regex, I thought, hmm, this would break if (your example above) .. then I stopped going down that road, and just finished my post. [1]

    As often happens, we were dealing with an incompletely specified problem. But even the discussion around the possible solutions is a worthwhile endeavour. :)

    1. "Just #$%@ing Do It." --petdance|alester, undated quotation

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.