Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?<phone>(\+?\d{1,4}?[-.\s]?)?(\(\d{1,4}?\))?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9})|(?<email>[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4})
/
gi

Description

Extract the phone numbers and email addresses from a string

Submitted by Mukesh Jangid - a year ago