Can you salvage my negative lookbehind example for commifying numbers?

后端 未结 3 731
旧时难觅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条回答
  •  旧时难觅i
    2021-02-04 05:12

    I don't think this is what you are after (especially becaue the negative look-behind assertion has been dropped), but I guess, your only option is to slurp up the decimal places like in this example:

    s/
      (?:
        (?<=\d)
        (?=(?:\d\d\d)+\b)
       |
        ( \d{0,3} \. \d+ )
      )
     / $1 ? $1 : ',' /exg;
    

    P.S. I think it is a good example when not used as the first one in the book, as it demonstrates some of the pitfalls and limitations of look-around assertions.

提交回复
热议问题