in reply to REGEX detailed character replace
Learn some regex-fu. :)
Alright, well, let's take what you have:
|xx-xxx-xxxxx-xxx x/xx|xx-xxxx-xxx-xx-xxxx-xx-xx|
Now re-write that in a way that we preserve what you want to keep:
|(xx)-(xxx)-(xxxxx)-(xxx) (x/xx)|(xx)-(xxxx)-(xxx)-(xx)-(xxxx)-(xx)-(x +x)|
Make that a bit more flexible:
Now you'll match all of the interesting bits, so let's set up the inline replace:|(\w{2})-(\w{3})-(\w{5})-(\w{3}) (\w/\w{2})|(\w{2})-(\w{4})-(\w{3})-(\ +w{2})-(\w{4})-(\w{2})-(\w{2})|
$mess =~ s/|(\w{2})-(\w{3})-(\w{5})-(\w{3}) (\w\/\w{2})|(\w{2})-(\w{4} +)-(\w{3})-(\w{2})-(\w{4})-(\w{2})-(\w{2})|/\1,\2,\3,\4\5,\6,\7,\8,\9, +\10,\11,\12/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: REGEX detailed character replace
by pjc955 (Initiate) on Nov 12, 2008 at 16:42 UTC | |
|
Re^2: REGEX detailed character replace
by furry_marmot (Pilgrim) on Nov 13, 2008 at 20:34 UTC |