0

I have seen this one-line perl code from the web when I searched Google "perl remove comma from numbers":

perl -pe 's/(?<=\d),(?=\d)//g' file

I don't understand ?<= and ?=

I understand that () is for grouping and capturing; (?:) is without capture; and s/// is to substitute, and g is to apply globally, and \d is digit; my own code is s/(\d),(\d)/$1$2/g

Can someone please tell me ?<= and ?= I cannot find explanation of this perl expression on the web.

Thank you very much!

ndnenkov
  • 33,260
  • 9
  • 67
  • 97
lisprogtor
  • 5,057
  • 8
  • 14
  • 1
    Look for `lookahead` and `lookbehind` – vks Aug 10 '15 at 17:14
  • 1
    http://perldoc.perl.org/perlre.html – tripleee Aug 10 '15 at 17:15
  • The zero-width predicates are mainly useful when a match cannot be consumed. Your pattern will fail to substitute one comma in `1,2,3` because 2 will be consumed before matching recommences. If you don't have matches of this type, your pattern is fine. – tripleee Aug 10 '15 at 17:18

0 Answers0