http://qs321.pair.com?node_id=11117037


in reply to Modification of a read-only value attempted

Also, when writing regexes to parse strings like this, watch out for "greedy." Ordinarily a regex will "greedily" try to match the longest possible string, and this is often the wrong thing to do here.
  • Comment on Re: Modification of a read-only value attempted

Replies are listed 'Best First'.
Re^2: Modification of a read-only value attempted
by ikegami (Patriarch) on May 21, 2020 at 14:50 UTC
    Ordinarily a regex will "greedily" try to match the longest possible string

    No.

    # Matches 2 chars at pos 0, not 6 chars at pos 2. "acabbbbc" =~ /ab*c/

    Greediness applies to individual regex atoms, causing those to match as much as possible at the current position.

Re^2: Modification of a read-only value attempted
by AnomalousMonk (Archbishop) on May 21, 2020 at 15:11 UTC

    Further to ikegami's reply:   The rule is to find the leftmost longest match. This has tripped me up more that once!


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