0

What I have: 123456789-987654321
What I need: 3456789-4321 (keep last 7 digits from 1st group and keep last 4 digits from 2nd group)

(\d{7})-         gets me 3456789-
((\d{4})$(?<=))  gets me 4321

I can't figure out how to combine the 2 to get what I need.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
JenL
  • 9
  • 1
  • This question should be closed due to the premises of having one match with skipped elements inside. Check it here: https://stackoverflow.com/questions/277547/regular-expression-to-skip-character-in-capture-group. – lemon May 13 '22 at 16:26

1 Answers1

0

You can match optional digits and then capture the 7 digits and the hyphen. Then match again optional digits and capture the last 4.

In the replacement use the 2 capture groups.

^\d*(\d{7}-)\d*(\d{4})$
The fourth bird
  • 154,723
  • 16
  • 55
  • 70