This blog post is firstly published on my personal blogging site kanby.net TL;DR Most common regex patterns Examples of regex patterns Most Common Patterns Important: a x b in this example a is preceeding by x and b is followed by x ^ means the start of each line in string $ means the end of each line in string () groups specific pattern (?:) means this pattern will match in string BUT will not return it. E.g., A phone number regex pattern must include country code but does not have to extract that part even though it must match on string. [] matches specified single character, e.g. [abc] will match a or b or c. Ranges are supported too [a-c] will match the same. [^] matches every character except specified ones . matches any single character * 0 or more of the preceding element + 1 or more of the preceding element ? 0 or 1 of the preceding element {n} Exactly n occurrences of the preceding element. {n,} n or more occurrences of the preceding element. {n,m} Between n and m occurrences of the preceding element \d any digit \D any non-digit \w any word character (alphanumeric + underscore) \W any non-word character \s Matches any whitespace character \S Matches any non-whitespace character \ escape character, e.g., İf you want to find . (which is a special character) in your string, you need to do this \. By combining these, you can create highly complicated pattern match/extraction functions with Regex. Examples \^[a-z_]+\.com$\ will match .com domains [a-z_] means characters from a to z and underscore + means at least one of them \. means period (.) com is for just com ^ and $ is for searching from the start of the string to the end of each line ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$ will match emails ^ Asserts the start of the string. [a-zA-Z0-9._%+-]+ Matches one or more characters that can be: Letters (a-z, A-Z) Digits (0-9) Underscores (_) Dots (.) Percent signs (%) Plus signs (+) Hyphens (-) @ Matches the "@" symbol which is mandatory in all email addresses. [a-zA-Z0-9.-]+ Matches one or more characters for the domain name, allowing: Letters (a-z, A-Z) Digits (0-9) Hyphens (-) Dots (.) \. Matches a literal dot (.) separating the domain name from the top-level domain (TLD). [a-zA-Z]{2,} Matches the top-level domain (TLD) consisting of at least two letters (e.g., .com, .org). $ Asserts the end of the string. If you have any questions, here is my Instagram @emrekanbay.en This blog post is firstly published on my personal blogging site kanby.net This blog post is firstly published on my personal blogging site kanby.net kanby.net TL;DR Most common regex patterns Examples of regex patterns Most common regex patterns Examples of regex patterns Most Common Patterns Important: a x b in this example a is preceeding by x and b is followed by x Important: a x b in this example a is preceeding by x and b is followed by x a x b a b ^ means the start of each line in string $ means the end of each line in string () groups specific pattern (?:) means this pattern will match in string BUT will not return it. E.g., A phone number regex pattern must include country code but does not have to extract that part even though it must match on string. [] matches specified single character, e.g. [abc] will match a or b or c. Ranges are supported too [a-c] will match the same. [^] matches every character except specified ones . matches any single character * 0 or more of the preceding element + 1 or more of the preceding element ? 0 or 1 of the preceding element {n} Exactly n occurrences of the preceding element. {n,} n or more occurrences of the preceding element. {n,m} Between n and m occurrences of the preceding element \d any digit \D any non-digit \w any word character (alphanumeric + underscore) \W any non-word character \s Matches any whitespace character \S Matches any non-whitespace character \ escape character, e.g., İf you want to find . (which is a special character) in your string, you need to do this \. ^ means the start of each line in string ^ $ means the end of each line in string $ () groups specific pattern () (?:) means this pattern will match in string BUT will not return it. E.g., A phone number regex pattern must include country code but does not have to extract that part even though it must match on string. (?:) [] matches specified single character, e.g. [abc] will match a or b or c. Ranges are supported too [a-c] will match the same. [] [abc] [a-c] [^] matches every character except specified ones [^] . matches any single character . * 0 or more of the preceding element * + 1 or more of the preceding element + ? 0 or 1 of the preceding element ? {n} Exactly n occurrences of the preceding element. {n} {n,} n or more occurrences of the preceding element. {n,} {n,m} Between n and m occurrences of the preceding element {n,m} \d any digit \d \D any non-digit \D \w any word character (alphanumeric + underscore) \w \W any non-word character \W \s Matches any whitespace character \s \S Matches any non-whitespace character \S \ escape character, e.g., İf you want to find . (which is a special character) in your string, you need to do this \. \ . \. By combining these, you can create highly complicated pattern match/extraction functions with Regex. Examples \^[a-z_]+\.com$\ will match .com domains [a-z_] means characters from a to z and underscore + means at least one of them \. means period (.) com is for just com ^ and $ is for searching from the start of the string to the end of each line ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$ will match emails \^[a-z_]+\.com$\ will match .com domains [a-z_] means characters from a to z and underscore + means at least one of them \. means period (.) com is for just com ^ and $ is for searching from the start of the string to the end of each line \^[a-z_]+\.com$\ [a-z_] means characters from a to z and underscore + means at least one of them \. means period (.) com is for just com ^ and $ is for searching from the start of the string to the end of each line [a-z_] means characters from a to z and underscore [a-z_] means characters from a to z and underscore [a-z_] + means at least one of them + means at least one of them + \. means period (.) \. means period (.) \. com is for just com com is for just com com ^ and $ is for searching from the start of the string to the end of each line ^ and $ is for searching from the start of the string to the end of each line ^ $ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$ will match emails ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$ ^ Asserts the start of the string. [a-zA-Z0-9._%+-]+ Matches one or more characters that can be: Letters (a-z, A-Z) Digits (0-9) Underscores (_) Dots (.) Percent signs (%) Plus signs (+) Hyphens (-) @ Matches the "@" symbol which is mandatory in all email addresses. [a-zA-Z0-9.-]+ Matches one or more characters for the domain name, allowing: Letters (a-z, A-Z) Digits (0-9) Hyphens (-) Dots (.) \. Matches a literal dot (.) separating the domain name from the top-level domain (TLD). [a-zA-Z]{2,} Matches the top-level domain (TLD) consisting of at least two letters (e.g., .com, .org). $ Asserts the end of the string. ^ Asserts the start of the string. ^ start [a-zA-Z0-9._%+-]+ Matches one or more characters that can be: Letters (a-z, A-Z) Digits (0-9) Underscores (_) Dots (.) Percent signs (%) Plus signs (+) Hyphens (-) [a-zA-Z0-9._%+-]+ one or more Letters (a-z, A-Z) Digits (0-9) Underscores (_) Dots (.) Percent signs (%) Plus signs (+) Hyphens (-) Letters (a-z, A-Z) Digits (0-9) Underscores (_) Dots (.) Percent signs (%) Plus signs (+) Hyphens (-) @ Matches the "@" symbol which is mandatory in all email addresses. @ "@" symbol [a-zA-Z0-9.-]+ Matches one or more characters for the domain name , allowing: Letters (a-z, A-Z) Digits (0-9) Hyphens (-) Dots (.) [a-zA-Z0-9.-]+ one or more domain name Letters (a-z, A-Z) Digits (0-9) Hyphens (-) Dots (.) Letters (a-z, A-Z) Digits (0-9) Hyphens (-) Dots (.) \. Matches a literal dot (.) separating the domain name from the top-level domain (TLD). \. literal dot (.) [a-zA-Z]{2,} Matches the top-level domain (TLD) consisting of at least two letters (e.g., .com, .org). [a-zA-Z]{2,} top-level domain (TLD) two letters $ Asserts the end of the string. $ end If you have any questions, here is my Instagram @emrekanbay.en @emrekanbay.en