in reply to Re^4: Regex conditional match if previous match in same expression is true?
in thread Regex conditional match if previous match in same expression is true?

$1 is a dynamically scoped variable that contains details from the last successful match in the current scope. It is NOT set to undef after a failed match.

Regarding your comments to ikegami, they dont seem so relevent here. I didnt use an eval operator, as for how to accomplish the goal with the conditional pattern and not alternation, well ive already done that havent I? If you mean regarding MRE, id say just work through the book. There is a way of thinking about things that makes regexes easy to understand, and there is a way that will lead to confusion. I dont recall specifically anything that gives a particularly good discussion of the conditional pattern. I have never encountered one in live code.

---
$world=~s/war/peace/g

  • Comment on Re^5: Regex conditional match if previous match in same expression is true?