0

Given a file containing multiple strings (one in each line) - among them there will be the following two strings:

de12_QA_IR_OS_HV
de12_IR_OS_HV

(the only difference is "QA_" in the right position).

I need to perform some action if the current line being handled contains one of the above. if yes, i should use the string value without the "QA_" substring.

I am using the following regexp to detect the values /de12_(QA_)?IR_OS_HV/ but is there a way to remove the "QA_" if it exist using the same regexp ?

1 Answer 1

1

You can capture what's before and after the QA_:

if (/(de12_)(QA_)?(IR_OS_HV)/) {
    print $1 . $3, "\n";

Or, use substitution

if (s/de12_(QA_)?IR_OS_HV/de12_IR_OS_HV/) {
    print $_, "\n";
}

But, in fact, you know what string to use if you the regex matches:

if (/de12_(QA_)?IR_OS_HV/) {
    print "de12_IR_OS_HV\n";
}
Sign up to request clarification or add additional context in comments.

2 Comments

Your last edit is right :) only if it was the only case... the input file contains many pairs of strings (having the "QA_" in one of them), and i tried to get a general way of handling them. Now i need to create a sub to handle all cases. Anyhow, your answer helped me...
@NirMH: repeat after me: "choroba has always the good answer". (note: you can do the same with Miller)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.