Skip to main content
added 3 characters in body
Source Link
Joe DeRose
  • 3.6k
  • 3
  • 30
  • 35

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

To allow an optional "+" at the beginning, follow it with a question mark to make it optional: /^+^\+?(9|8)[0-9]{9}/.

To allow any character except "0", replace the (9|8) with a construct to accept only 1-9: /^+^\+?[1-9][0-9]{9}/.

And in your example, the phone number doesn't come at the beginning of the line, so the caret will not find it. If you're looking for content in the middle of the line, you'll need to drop the caret: /+\+?[1-9][0-9]{9}/.

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

To allow an optional "+" at the beginning, follow it with a question mark to make it optional: /^+?(9|8)[0-9]{9}/.

To allow any character except "0", replace the (9|8) with a construct to accept only 1-9: /^+?[1-9][0-9]{9}/.

And in your example, the phone number doesn't come at the beginning of the line, so the caret will not find it. If you're looking for content in the middle of the line, you'll need to drop the caret: /+?[1-9][0-9]{9}/.

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

To allow an optional "+" at the beginning, follow it with a question mark to make it optional: /^\+?(9|8)[0-9]{9}/.

To allow any character except "0", replace the (9|8) with a construct to accept only 1-9: /^\+?[1-9][0-9]{9}/.

And in your example, the phone number doesn't come at the beginning of the line, so the caret will not find it. If you're looking for content in the middle of the line, you'll need to drop the caret: /\+?[1-9][0-9]{9}/.

added 405 characters in body
Source Link
Joe DeRose
  • 3.6k
  • 3
  • 30
  • 35

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

More to come onTo allow an optional "+" at the rest of yourbeginning, follow it with a question mark to make it optional: /^+?(9|8)[0-9]{9}/.

To allow any character except "0", replace the (9|8) with a construct to accept only 1-9: /^+?[1-9][0-9]{9}/.

And in your example, the phone number doesn't come at the beginning of the line, so the caret will not find it. If you're looking for content in the middle of the line, you'll need to drop the caret: /+?[1-9][0-9]{9}/.

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

More to come on the rest of your question ...

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

To allow an optional "+" at the beginning, follow it with a question mark to make it optional: /^+?(9|8)[0-9]{9}/.

To allow any character except "0", replace the (9|8) with a construct to accept only 1-9: /^+?[1-9][0-9]{9}/.

And in your example, the phone number doesn't come at the beginning of the line, so the caret will not find it. If you're looking for content in the middle of the line, you'll need to drop the caret: /+?[1-9][0-9]{9}/.

Source Link
Joe DeRose
  • 3.6k
  • 3
  • 30
  • 35

Your regex pattern seems to be designed to allow a 9 or 8 at the beginning, but it would be better to enclose that choice in parentheses: /^(9|8)[0-9]{9}/.

More to come on the rest of your question ...