Good point -- I was only answering the follow-up, not the reply. And now I've spent an entertaining hour tinkering with Perl regular expressions, time which is never wasted. :)
Here's my improved code, which shows that I still have some distance to go in writing regular expressions:
tab@music3:~/2018-0717$ cat !$ cat pm2.pl #!/usr/bin/perl use strict; use warnings; { my $word = q($-.%abc&/); my @group1 = ( $word =~ m/(?: # Non-capturing group of captured ([^a-zA-Z]+) # .. non-matching ([a-zA-Z]+) # .. following by matching )+ # .. for as many groups as possible ([^a-zA-Z]+) # followed by matching. /x ); my @group2 = map { $_ =~ /[a-zA-Z]/ ? split( //, $_ ) : $_ } @group1; my $new_word = join ( '', map { "[$_]" } @group2 ); print "$word -> $new_word\n"; } tab@music3:~/2018-0717$ perl pm2.pl $-.%abc&/ -> [$-.%][a][b][c][&/] tab@music3:~/2018-0717$
In reply to Re^7: regex find and replace with a twist
by talexb
in thread regex find and replace with a twist
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |