yacky yacky - 1 month ago 7
Java Question

Get mobile numbers and passwords from a string

What regular expression should I use in order to get mobile numbers from strings like the following example?

What regular expression should I use to get meeting passwords from strings like the following example?

MTW-08 Party-Bridge25 - PH: +91-80-30912334
+91-80-43452300 Extn: 11200; Meeting ID - 882004 ;
Meeting Password – 1234

qzb qzb
Answer

You provided only two examples, and I'm not sure if all numbers in you real data follows the same format. But if they are, following regexp will match to these numbers:

(\+\d{2}-\d{2}-\d{8})

Where:

  • \d matches to any digit (0-9)
  • {2} specifies how many times digit must be repeated, it this case - 2

You can also match only numbers which starts with +91 prefix using this regexp:

(\+91-\d{2}-\d{8})
Comments