Regular Expressions Syntax
Syntax-focused lesson of regular expressions
We'll cover the following...
We know that regular expressions are used for pattern matching. Let’s look at how to write and understand a RegEx.
Syntax
A regular expression can find a matching substring or test if a string passes a certain criterion. Let’s look at the syntax of RegEx.
Brackets
Brackets, or square brackets []
, are patterns that find a range of characters in the string. The brackets encapsulate the criteria or pattern that the string needs to satisfy. This chart shows how brackets are used.
Expression | Description |
---|---|
[...] |
Any of the characters encapsulated in the brackets with ... representing any character or pattern. |
[^...] |
Not any character encapsulated in the brackets where ... represents any character or pattern. The ^ represents Not. |
[0-9] |
Any number between 0 and 9 |
[a-z] |
Any character from lowercase letter ‘a’ to lowercase letter ‘z’ |