P is for Practical | |
PerlMonks |
Re: Replace characters within stringby hv (Prior) |
on Sep 07, 2022 at 22:08 UTC ( [id://11146756]=note: print w/replies, xml ) | Need Help?? |
For the third part, if I understand the requirement correctly, you could achieve it with something like this:
Note that this uses a lookahead to match the second copy of the bracketing character, to ensure that all matches can be replaced with a single invocation - I assume we want to allow "IUIUI" to be translated to "IIIII". The same approach can also be used to simplify the head and tail matches:
Note that I have ignored your assertion in the first case that the sequence of initial Us must be followed by one of I, O, P, B, M since that appears to be guaranteed; I've also ignored the assertion in the second case that the sequence of final Us must be preceded by I or O, since you don't anywhere say that that is required. (If it _is_ required, I'd use a lookbehind for that assertion.) Hope this helps
In Section
Seekers of Perl Wisdom
|
|