0

I want this regex to remove everything except one match, the regex is matching the digits right but i want to negate it so it will only leave the 11 first digits match

So if i have like blablalbla: cool - 12345678900 blablabla: - 2/22/2222 cool 19292 The regex matches the digits (12345678900) as i want to, but i need it to match everything else than the 11 digits

Here is the regex: (\d{11})

I read some things on regex101 and regexr, tried doing some live regex test but i didnt figured out how to do that

I saw that "^" also works as a negation but i tried that and it seems doesnt work, how should i do that negation and can you explain please, thank you so much <3

ANSWER: got it working with ^.*(\d{11}).*$ and replacing with $1

  • Split with `\d{11}` – Wiktor Stribiżew Jul 30 '20 at 22:53
  • You are matching the whole string and replacing it with the contents of capture group 1. You could also simply replace the string with the match of `\d{11}`. If there is more than one such match you could take just the first or use some or all in whatever way that suits your purposes. – Cary Swoveland Jul 31 '20 at 05:14

0 Answers0