Can you salvage my negative lookbehind example for commifying numbers?

后端 未结 3 729
旧时难觅i
旧时难觅i 2021-02-04 04:44

In the \"Advanced Regular Expresssion\" chapter in Mastering Perl, I have a broken example for which I can\'t figure out a nice fix. The example is perhaps trying to be too clev

3条回答
  •  忘了有多久
    2021-02-04 05:05

    I don't think it's possible without some form of variable-width look-behind. The addition of the \K assertion in 5.10 provides a way of faking variable-width positive look-behind. What we really need is variable-width negative look-behind but with a little creativity and a lot of ugliness we can make it work:

    use 5.010;
    $_ = '$1234567890.123456789';
    s/(?

    If there was ever a pattern that begged for the /x notation it's this one:

    s/
      (?

提交回复
热议问题