Last updated on 14 Dec 2016 | Posted on 28 Nov 2016
If you haven't already, I'd recommend reading the regex reference I've previously written. It help give you the meaning of each character in a regular expression as well as ways that you can change the meaning of a character or what you wrap it, such as braces and brackets.
The character that indicates the 'start' of a string is ^ and $ indicates the 'end'.
The above means that the string must start with the word "Expression".
The above means that the string must end with the word "Expression".
You can then combine the two into something like this:
This expression will only allow the words "Regular Expression".
To make it a little bit more dynamic you could change the above to:
This matches any characters from a to z (lower case), any number of times.
If we introduce capital letters and numbers as well, all we need to add is:
If we introduce a dot (period) which matches any single character, we could enforce any 5 characters from start to end, like so:
In this case, the number inside the braces refers to the number of required reptitions of any single character.
As we've just seen, brackets can be used in expressions, and often are. To begin with:
Matches either an 'x' or a 'y'.
Matches any letters between 'o' and 'z'.
Matches any letter (case insensitive) at the start of a string.
The '^' can also be used to negate something. The following means NOT an upper or lower case character between a and f or A and F:
Or NOT 0 to 9: