0

In an intermediate output, I'm getting a string like:

+91 87774 44444‬ (64 messages):

I tried using this regex but it is returning false:

(^\\+\\d{2} \\d{5} \\d{5} \\(\\d* \\w*\\):)

Can anyone explain me this, and also provide correct answer? I'm using Netbeans IDE.

The message contains a null character at the end, that's why I can not match the pattern...

  • 3
    Pretty much answered here: https://stackoverflow.com/questions/18351553/regular-expression-validation-for-indian-phone-number-and-mobile-number – maio290 Jul 20 '18 at 20:31
  • (^\\+\\d{2} \\d{5} \\d{5} \\(\\d* \\w*\\):) ^ defines that the patter must start at beginning of a new line \\+ selects the + \\d indicate Any digit, short for [0-9] so \\{2} means you are searching 0-9 in next two digit Same goes for this \\d{5} \\d{5} for next 5 digit then again 5 digit * indicates, Occurs zero or more times, is short for {0,} \w indicates, as metacharacter and used to find a word character. I am not sure but by using this may be you are skipping every other character \\(\\d* \\w*\\) – Shadab Siddiqui Jul 20 '18 at 20:55

1 Answers1

-1
\+[0-9]{2}\s[0-9]{5}\s[0-9]{5}

+ and the numbers thereafter \+[0-9]{2}

Space \s

Another 5 numbers [0-9]{5}

Space \s

Last 5 numbers [0-9]{5}

You can use online Java Regular Expression

enter image description here

Husam Ebish
  • 4,893
  • 2
  • 22
  • 38