in reply to Re: Shortest way to replace a string
in thread Shortest way to replace a string

Or
s/(?<=30\.00\.)[0-9][0-9]\.[0-9][0-9]/00.00/g
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^3: Shortest way to replace a string
by BrowserUk (Patriarch) on Sep 11, 2013 at 23:15 UTC

    The spec was "shortest" and that's 10 keystrokes longer; and certainly no more efficient :)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Short? How about this?

      s/^(30\.00).*? /$1.00.00 /;

      UPDATE: Added the missing space in the "replace" bit.

        s/^(30\.00)\S+/$1.00.00/;

        is two fewer.

      It does not match ٧, though.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        It does not match ٧, though.

        Deliberately so.

        The day anyone shows me a real program doing math with non-Hindu-Arabic numerals, I'll consider that as a requirement.

        And then disregard it completely unless it is explicitly specified.

        In just the same way that I do not walk around permanently looking up -- just in case an iceberg should fall from the sky -- I do not program to cater for marginal, statistically unlikely, possibilities, unless there is some realistic expectation that they may occur.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.