in reply to Re: 1000000th question about regex lol (updated)
in thread 1000000th question about regex lol

Yes, I am sorry. Here is the explanation: I wanted to write a sub that does not always replace every occurrence of a substring. The caller can specify to only replace the first two matches or the last three matches or anything. But when every single match has to be replaced, I realized that I can use a regex to do that. But the regex replace doesn't get to run unless you omit the fourth argument.
  • Comment on Re^2: 1000000th question about regex lol (updated)

Replies are listed 'Best First'.
Re^3: 1000000th question about regex lol (updated)
by AnomalousMonk (Archbishop) on Dec 07, 2019 at 20:24 UTC
    The caller can specify to only replace the first two matches or the last three matches or anything.

    By "or anything", do you mean that it should be possible to replace a substring that's somewhere in the middle, but not anchored at either end? My understanding of the code and discussion so far is that any sequence of substring replacements must be anchored to an end of the string, but "or anything" makes me wonder. If you have a counterexample, please post it as a test case.


    Give a man a fish:  <%-{-{-{-<

      Oh, sorry. By "anything" I meant any number.