1

I am trying to write a regex to match a pattern like

7777-555-999

The pattern is valid only if all four digits are same as first digit like 7777.If first digit is 6 then first four digits should be 6666 . similarly for next 3 and the last 3. How to match exact digit as first.kindly update

user2779311
  • 1,688
  • 4
  • 23
  • 31
  • 1
    try `(\d)\1{4}` – Ghost Ops Oct 01 '21 at 06:27
  • how can we modify this to digits in increasing order. like 789-345-234. What regex would work for this. – user2779311 Oct 03 '21 at 15:38
  • What do u mean? so u want to replace the numbers in `7777-555-999` with their incremented value? Pls post the demo input and output pls... – Ghost Ops Oct 03 '21 at 18:02
  • no the input now is 789-345-234 and it should be validated only if numbers are in consecutive order i.e 789 or 123 or 345 like this. how to write regex for it. – user2779311 Oct 04 '21 at 06:23
  • i think it is a little bit challenging, it can be only done by putting all the possible combinations into a regex like [`(?:(?:012|123|234|345|456|567|678|789)[\s-]){3}`](https://regex101.com/r/b1k6UT/1) i'll update you later if i find something like that in a regex way rather than this type of finding text by their all type of combinations – Ghost Ops Oct 04 '21 at 07:02

0 Answers0