NINJA-REGEX
This is mainly for my understanding of Regex as well as its functions and uses predominantly in Python3 as well as in its use in BASH shell scripts and UNIX grep, awk and sed
Last updated
Was this helpful?
This is mainly for my understanding of Regex as well as its functions and uses predominantly in Python3 as well as in its use in BASH shell scripts and UNIX grep, awk and sed
Last updated
Was this helpful?
Any first character from [a-z]inja
will match as below. However any capitals are ignored
The range a-z can be written as [a-z]inja. Dont have to include all the way to 'z' but a-f or s-w, or whatever we require.
[a-zA-Z0-9]inja will match the first charachter from a-z or A-Z or 0-9
Telephone number:
11 numbers [0-9]{11} - This will match 11 numbers exactly
Between 5-8 numbers [0-9]{5,8}. If you want AT LEAST 5 numbers [0-9]{5,} --we just leave the comma with nothing after and close the braces
There are 12 characters with special meanings and are called "METACHARACTERS". These metacharacters add more functionality and meaning when matching strings. They are:
METACHARACTERS
DESCRIPTION
EXAMPLE
\ Backslash
Signals a special sequence (can also be used to escape special characters)
\d
^ Caret
Starts with
^hello
$ Dollar Sign
Ends with
world$
. Period
Any character (except newline character)
h..o
| Pipe
Either or
stay | go
? Question Mark
Preceding character is optional
colou?r
matches color and colour
* Asterix
Zero or more occurrences
aix*
+ Plus
One or more occurrences
aix+
( ) Parenthesis
Capture and Group
[ ] Square Bracket
A set of characters
[a-m]
{ } Curly brace
Exactly the specified number of characters
{2,4}