doc icon indicating copy to clipboard operation
doc copied to clipboard

Show ways to perform a "chain" of regex substitutions

Open schultzdavid opened this issue 1 month ago • 2 comments

In real-world text processing problems (including one-liners), it's not uncommon that one wants to apply several substitution regexes one after another, transforming the input text one step at a time. The docs (probably a new subsection at the bottom of language/regexes#Substitution) should expressly show a few ways to do that.

One such way could be

for lines() -> $_ is copy { 
    s/a1/a2/; 
    s/b1/B1;
    .say
}

I could write the text myself this week, but it would be good to first hear what are the "best" ways to accomplish that. (I do think that's fitting in the reference doc on regexes, because for each regex substitution operator it is of inherent interest if and how one can chain it.)

schultzdavid avatar Nov 16 '25 23:11 schultzdavid

https://stackoverflow.com/a/65077600/7270649

jubilatious1 avatar Nov 20 '25 05:11 jubilatious1

Actually I quite like the answer in this comment, which i believe might be from @alabamenhu ?

https://stackoverflow.com/questions/65066358/concatenating-s-in-raku/65077600#comment115088438_65077600

jubilatious1 avatar Nov 20 '25 05:11 jubilatious1