I have inherited a perl script that pulls data out of some files. The whole script works fine but recently some engineers have been putting in more than one number for a certain spot that usually took one number, so the output is not showing all of what is expected.
Sample input:
CRXXXX: "Then some text"
CRs XXXX, XXXX, XX, XXX
CRXXX "Some Text"
Currently this regex statement I have pulls out the number after the CR, but if given then second line of sample input it prints "s XXXX, XXXX, XX, XXX" instead of the wanted "XXXX XXXX XX XXX"
I am very new to perl and am struggling to figure out how to alter this regex to work on all of the inputs.
$temp_comment =~ s/\s[cC][rR][-\s:;]*([\d])/\n$1/mg;
Thanks in advance!
Brock
For sample data like:
try:
or, if you want to stay close to the string templates:
but you’d have to remove the commas in the number group in a subsequent step.
or
For “single step”, you have to use the
/emodifier:This will, on the data above, result in:
But really, please use, if possible, the simpler two step approach. The latter regex might be a maintainance nightmare for your successors.