Basic Regex

Basics of Regular Expressions

Match
Don't match
Match A or B

You can match a word by putting it between two brackets.

As example, this will only match the word "Dinosaur": (Dinosaur)

If you don't want to match something you will have to put a ?: before it.

As example, this will not match the word "Donkey": (?:Donkey)

You may also want to catch multiple options, for that we use a "Vertical bar" or also known as a "Pipe" between linux users.

As example, this will match if either "Cat" or "Dog" is present: (Cat|Dog)

To match anything of any length, use (?).

Character classes

Words
Characters
Special Characters

To match a word, you put it between two brackets.

Example: (Banana)

For matching characters there are multiple options:

Matching specific characters:

For matching a specific character, you put them in square brackets.

This will match A, B and C: ([abc])

This will match every character from a-Z: ([a-Z])

This will match every number: ([0-9])

Sometimes you have to use special characters but it may cause conflicts. In this case, you will have to use an escape character.

For example, this is a star that doesn't interfere with other matches \*.

Understanding Regex

If you still do not know what Regex are or want to know more. Check out the cheat sheet on the site below.

Great tools for writing and testing Regex

‚Äč