I've been working on this for a while today, and I must just be missing something obvious
I'm receiving a string of characters that contains occasional 'special characters' (two slashes with an alpha character between them) that I need to convert back to their regular form.
Specifically, I need to convert:
If you've ever worked with HL7 messaging protocol, you may have seen this before. (Basically, these five characters are message control characters, so the \x\ notation is how it lets you know to replace them with the reserved character)\F\ to | \S\ to ^ \T\ to & \R\ to ~ \E\ to \
Anyways, I started with the following:
And that *almost* works perfectly. Where it doesn't work is if there's two of these special characters grouped around a normal character... For example, the string:$msgu =~ s/\\F\\/\|/g; $msgu =~ s/\\S\\/\^/g; $msgu =~ s/\\T\\/\&/g; $msgu =~ s/\\R\\/\~/g; $msgu =~ s/\\E\\/\\/g;
should translate to:"AB\T\F\S\CD"
but it ends up as:"AB&F^CD"
because I'm doing the global match on \F\ first. And since I can get these in any order, there's no way to put them in an order that always works."AB\T|S\CD"
So, what I *really* need is a way to do this 'left-to-right' where it finds the first \x\ character, and then translates it (if it's one of the valid 5), and then continue from there. Doing whichever comes up next in the string
Any advice for me to try or place I should be looking?
Trek
In reply to Pattern Matching, left-to-right by TrekNoid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |