Regular Expressions
Asterisk on STEROIDS !!
Resources
Introduction
This introduction will enable us to do the following:
Describe Regular Expressions
Use regular expressions to match basic patterns
Describe RegEx Metacharacter
Practise Regular Expressions using https://regex101.com or https://regexr.com
METACHARACTER
METACHARACTER NAME
MEANING
1
^
caret
Matches the beginning of the string, or the beginning of a line if the multiline flag (m
) is enabled. This matches a position, not a character.
2
$
dollar sign
Denotes the END of a regular expression or ending of a line
3
[ ]
square bracket
Specifies a range of characters you wish to match
4
( )
parenthesis
Check for a string. Create and store variables
5
?
question mark
Check for zero or one occurrence of the preceding character .... zero or one instance
6
+
plus sign
Check for one or more occurrence of the preceding character .....one or more instances
7
*
multiply sign
check for any number of occurrences (including zero occurrence) of the preceding character ... zero or more instances
8
.
dot
check for a single character which is not the ending of a line......Any single character
9
|
pipe
Logical OR
10
\
escaping character
Escape from the normal way a subsequent character is interpreted
11
!
exclamation mark
Logical NOT
12
{ }
curly brackets
Repeat preceding character
13
-
dash
Used to specify range ie [0-9]
Using the websites above (eg https://regexr.com ) in the text field we have written some text to be searched by regex with the global and multiline selected. I will remove the multi-line option to keep it as close to normal regex as possible.
What is RegEx
RegEx is the shortened word for Regular Expression. A regular expression is a way of searching through text files - such as logfiles etc. in an efficient and painless way as possible. We can also do advanced 'find and replace.
^a . . .s$
The caret means "at the beginning
Last updated