in reply to Shift regex search back 4 characters...
G'day tj999,
Welcome to the Monastery.
Before seeing other responses, my first thought was a lookbehind assertion:
/(?<=222,)(\d{3})/g
Having seen other solutions, I think this is clearer than embedding a capture in an assertion.
Here are some tests using your example string and the two others used in earlier replies.
$ perl -E 'say for "222,222,123" =~ /(?<=222,)(\d{3})/g' 222 123 $ perl -E 'say for "222,345,222,678,222,222,543,111" =~ /(?<=222,)(\d{ +3})/g' 345 678 222 543 $ perl -E 'say for "123,222,456,222,222,111,222,999" =~ /(?<=222,)(\d{ +3})/g' 456 222 111 999
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Shift regex search back 4 characters...
by BillKSmith (Monsignor) on Mar 04, 2017 at 15:37 UTC | |
by AnomalousMonk (Archbishop) on Mar 04, 2017 at 20:53 UTC |