-2

I just need to find phone number in description and remove it using regular expressions. Phone numbers would be in following formats:

  • 998991234567
  • +998 99 123 45 67
  • 1234567
  • 991234567
  • (998)901234567

I have found following regex, but do not know what to change: /^(+\d{1,3}[- ]?)?\d{12}$/

Natlus
  • 57
  • 7
  • Do you know what your regex does? Can you formulate regexes for each sample of it's own and have problems combining them or are you stuck at one of these? – Sebastian Proske Jun 22 '18 at 12:07

1 Answers1

0

Based on your example of numbers format, this regex will work

/([0-9]{12})|(\([0-9]{3}\)[0-9]{9})|(\+[0-9]{3} [0-9]{2} [0-9]{3} [0-9]{2} [0-9]{2})|[^0-9]([0-9]{7})[^0-9]|[^0-9]([0-9]{9})[^0-9]/gm

You can use the pip | character to set more than one regex format to match.

Also you can test your regex in https://regex101.com/r/fzB1nL/1

Ayoob Ali
  • 31
  • 5