Ok ok.. loosen your belts.. rolls your eyes, crack your knuckles or maybe close your eyes and randomly punch the keyboard - here's a regex question!
I have a string as such: 423RY75Y69827EC67592C78657N965R
It has to be turned into 423R_Y75Y_69827E_C67592C_78657N965R
What's the idea? The idea is, first and foremost.. if any digits are sandwiched between two letters, then put an underscore to the sides of this group... However, treat N characters as we would digits.
#!/usr/bin/perl -w use strict; use Smart::Comments; my $string = '423RY75Y69827EC67592C78657N965R345U299M'; my $correct = '423R_Y75Y_69827E_C67592C_78657N965R_345U_299M'; $string=~s/([A-MO-Za-mo-z])([\dN]+)\1/_$1$2$1_/g; ### $string # is now '423R_Y75Y_69827E_C67592C_78657N965R345U299M' # now i have troubles.. # the idea is to match right to left, and if after (the last digit # or N char), place an underscore, unless of course, that char is the # char we started with! $string=~s/([^\dN\3])([\dN]+)([A-MO-Za-mo-z])/$1_$2$3/g; ### $string # is now '423R_Y_75Y__69827E_C_67592C__78657N965R345U_299M' # wow, seems to have done the reverse of what i wanted!
I'm having real trickies here . . it's like reverse memory or something that the regex has to do.. ow..
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |