Regex. [] - {}^$*+?() |

·

2 min read

. (dot) It's going to search for any character inside your string. You can see that the regex found 48 occurrences on the string provided.

If you want to find the .(dot) itself, you need to use the \ escape character. Like \.
If you want to use any kind of special character, you have to escape it with \.

Let's suppose we want to find now any character that has bal and the next character should be any other.

Also, the .(dot) means the number of times you want to find the character.

\s Search all spaces

\S Search anything that is not space

\w Search for numbers and Letters

\W Search for everything that is not numbers and Letters

\d Seach for only numbers

\D Seach for anything that is not a number.

[] Understand it like or condition. In this example, it will search for all parts where r or b are before the letter e. See the example.

[a-z] Search only letters in lowercase

[A-Z] Search only letters in upper case

[0-9] Search only numbers

{} Use to specify the number of times you want something. Like the word we followed by 9 letters l.

Also, you can use it like this: The word we followed by 2 or 9 l

^ String that is at the beginning of the line

$ String that is at the end of the line

[^rb] When you use ^ inside the [], it is a not. It should be not r and not b before something

.* It will search parts at the line that starts with w, with anything in the middle and ends with k.

Another example is something that starts with w and ends with anything.

+ Matches one or more occurrences of the character.

a+
a+8
[0-9]+

? It will find any part that starts with e and contains or does not contain a space in the middle and the last string is the word Here

() | It will work similarly to the []. But the () will create a group.

(?<=l)(.*)(?=a) everything between l and a

Here you have a brief of everything: