Java OCA OCP Practice Question 3176

Question

Which of the following regular expressions is the correct expression for matching a mobile number stored in following format:

+YY-XXXXXXXXXX 

YY is the country code, the rest of the number is a mobile number?.

  • A. "\+\d{2}-\d{10}"
  • B. "\b\+\d{2}-\d{10}\b"
  • C. "+\d{2}-\d{10}"
  • D. "\b+\d{2}-\d{10}\b"


A.

Note

You need to provide a backslash as an escape character for "+".

Another important point is that you cannot use "\b" in starting and ending if the first or last character of the string is not a word character.




PreviousNext

Related