Useful Regex – Examples

Retrieve a name from a customer (ignore special characters of type *.-+/)

((\p{L}.?\s?){3,}\d{0,})

Find a word only if it is followed by a question mark but without taking the question mark

(^|\s)[a-zA-Z]+(?=\?)

Find a digit that is not followed by a comma or other digit

(^|\s)[0-9]+(?!(\,|[0-9]))

Retrieve domain names from sites

(?<=http:\/\/|https:\/\/)([a-zA-Z-0-9]+.)?([a-zA-Z0-9.-]+(?=.))

5 or 6 digit number that starts with “000”

((^|\s)000[0-9]{2,3}($|\s))

Retrieve a phone number (Fr)

(((+33|0)[0-9][\s.-]?)([0-9]{2}[\s.-]?){4})

Retrieve an email

([a-z]+.[a-z]+[0-9]{1,3}@[a-z]+.[a-z]+)

Recover a rate

([0-9]+[.,][0-9]+\s?%)

Retrieve a Postal Code (Fr)

(\s[0-9]{5}\s)

Find a number that is not preceded by “Order” or “Cde”

((?<!Commande\s|Cde\s))[0-9]+

Capture a decimal amount with 2 digits after the decimal point

[0-9]+[,.][0-9]{2}

Retrieve an invoice number in the form: FF-xxxxx or FC-xxxxx (Where x is a number)

(FF|FC)-[0-9]{5}

Retrieve the employee’s first and last name without (Mr.,Mrs,Miss …)

(?<=(M|Mme|Mlle)(\s*)).+