Regex Wildcard Character – A Complete Guide

Regex Wildcard Character

What is the wildcard character in regex? In regular expressions, a wildcard character is represented by a period “.” and will match any character. They are often combined with quantifiers, for example, the zero-or-more quantifier * to match a string of any character length or a specific quantifier (e.g. {5}) to match a string of … Read more »

Regex for Prices

Regex for Prices

Price tags come in various shapes and sizes around the Internet. Some have 2 decimal digits (e.g. 0.99), others include a currency symbol (such as $8.79), and some have neither (e.g. 100). Is it possible to write a regular expression to match these? A regular expression to match prices should preferably look for at least … Read more »

Regex Character Classes – A Complete Guide

Regex Character Class

What is a regex character class? In regular expressions, a character class allows one to define a custom set of characters that are allowed in a match. It is written by enclosing the allowed characters with square brackets e.g. [abc]. A negated character class denoted by [^…] can be used to match any character except … Read more »

Regex to Match Text Between Square Brackets

Regex Between Square Brackets

Regex can be used to extract portions of a string enclosed in brackets or another set of paired symbols, perhaps to use the contents or to delete the contents. There are various ways of extracting portions of a string between square brackets. One method involves a wildcard character along with the opening and closing square … Read more »

Regex for Spaces

Regex for Spaces

Isn’t it nasty when a piece of text contains multiple consecutive spaces where they shouldn’t be? Or extra spaces at the start or end of a piece of string? Regex can be used to tidy up these in no time. A regular expression for matching spaces should look for the space character / / or … Read more »

Regex Alternation (OR) – A Complete Guide

Regex Alternation

What is regex alternation? In regular expressions, the alternation character (|) is used to match one expression OR another. One can use it by placing the alternation character between two possible expressions (a|b). Alternation can be global across the entire expression, or local when enclosed in parentheses. For example, the following expression will match either … Read more »

Regex To Match Everything Before a Specified Character or Symbol

Regex to Match Everything Before a Character or Symbol

It is sometimes necessary to extract a part of a string before a specific character. For instance, you might want to extract the “user” part of an email address before the @ symbol. A regular expression to match everything before a specific character makes use of a wildcard character and a capture group to store … Read more »

Regex Anchors – A Complete Guide

Regex Anchor

What is a regex anchor? A regex anchor ensures that a matched expression is anchored to a certain position in the string. The start-of-string anchor (^) ensures it’s at the start of the string while the end-of-string anchor ($) ensures it’s at the end. A word boundary (\b) ensures it’s at the start or end … Read more »

Regex To Allow Not Only Whitespace

Regex For Not Only Whitespace

A RegexLand reader recently posted this question. Which regular expression can be used to match a string that is not only whitespace? A regex to match a string that does not contain only whitespace characters can be written in two ways. The first involves using wildcards (.) and the non-whitespace character set (\S), while the … Read more »

Regex Quantifiers – A Complete Guide

Regex Quantifier

What is a regex quantifier? A regex quantifier specifies the number of consecutive occurrences of the character or expression directly preceding it. Quantifiers can specify zero-or-more (*), one-or-more (+), zero-or-one (?), a specific quantity such as three {3}, more than three {3,}, or between one and three {1,3}. A lazy flag (?) added behind any … Read more »