Regular Expression and sed command: echo 123456789

2019-08-29 06:49发布

问题:

source is 1234567890, the regular expression ((?<=\d)\d{3})*\b can match: 234567890, so i think sed should replace 234567890 with TEST, but the result is: 1234567890, why?

回答1:

look-behind is not supported by sed. you could try ssed (super sed), it supports perl mode, (-R) then you could pass perl style regex to it. e.g. look ahead/behind.

see the feature list:

https://launchpad.net/ssed



回答2:

You need to rewrite the regex without lookbehind:

s/(\d)(?:\d{3})*\b/\1TEST


标签: regex linux sed