in reply to Re^3: regex in REPLACEMENT in s///
in thread regex in REPLACEMENT in s///

Could this be (sensibly) rewritten without the parenthesis? $example =~ s/hiss(es)?/leak/;

Although tybalt89 probably can think of some ways, my answer would be: No, I would keep the parentheses in that case. However, they can be made non-capturing by writing /hiss(?:es)?/ (or with the /n modifier, new since 5.22). I think choroba's point was that in s/(\d)/3/g, the parens serve no purpose at all.

Replies are listed 'Best First'.
Re^5: regex in REPLACEMENT in s///
by Bod (Parson) on Sep 13, 2023 at 10:42 UTC
    Although tybalt89 probably can think of some ways, my answer would be: No

    I am sure that tybalt89 and other wizards in The Monastery could contrive something that would have the same functionality...that's why I added "sensibly" to my question!

    Thanks for clarifying - I thought that was the case but I am far from being a regexp wizard so I wanted to check. Now I need to go and look up the /n modifier as that is new to me. I need to look up others as well as the only ones I ever use are /igc I think although I feel there is at least one more I use occasionally!