php - regex match string of exactly 6 numbers in text that has telephone numbers as well -


i have blocks of free text contain phone numbers , multiple 6 digit numbers need capture. 6 digit number has optional ','.

examples of 6 digit numbers 123456, or 123,456, need differentiate phone number 1 234 456 8901

i have :

    preg_match_all(",\[\w_][0-9]{3}(?:,)[0-9]{3}[\w_][\d]\d",$html, $value);  

is there better way this?

it's bit difficult review regex without sample input couple of observations:

  • [0-9] can replaced \d (since, you're using @ end)

  • [\d] same \d. it's character class , unless have more characters include it'ss fine without being enclosed in [].

  • (?:,) should , because neither want capture nor has quantifiers.

  • ,\[\w_] here seems want use character class \ escape first [. if need literal \ there; need escape \\ since it's special character.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -