Find the location with a match, then run a replace from that point on.
#!/usr/bin/perl use strict; use warnings; while(<DATA>) { if( m{ \A OBX \| [^|]* \| }gmsx ) { s{ \G (?: ([[:upper:]]) | ([[:lower:]]) | ([^\^]) ) }{ defined $1 ? "U$1" : defined $2 ? "L$2" : $3 }sexmg; } print; } __END__ NTE||L|obr note OBX|NM|aaA..^Haem^RD2|7.5|g/dL|13.0-18.0|OR| NTE||L|obx note 1/1 for 3058 OBX|NM|dBf..^TWC^RD2|8.9|10*9/L|4.0-11.0||
Makeshifts last the longest.
In reply to Re: Can anyone make this regex job neater?
by Aristotle
in thread Can anyone make this regex job neater?
by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |