Regular Expressions 101

Community Patterns

Extract phone number and email address from string

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 - 7 months ago