SlideShare a Scribd company logo
Your Ultimate Cheatsheet
AIML Enthusiast
Om Pramod
By OM PRAMOD
1
The Python Regex Handbook: Your Ultimate Cheatsheet
Period (.)
By OM PRAMOD
2
The Python Regex Handbook: Your Ultimate Cheatsheet
* (Asterisk)
By OM PRAMOD
3
The Python Regex Handbook: Your Ultimate Cheatsheet
Caret (^)
By OM PRAMOD
4
The Python Regex Handbook: Your Ultimate Cheatsheet
$ (Dollar)
By OM PRAMOD
5
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
6
The Python Regex Handbook: Your Ultimate Cheatsheet
+ (Plus)
By OM PRAMOD
7
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
8
The Python Regex Handbook: Your Ultimate Cheatsheet
? (Question Mark)
By OM PRAMOD
9
The Python Regex Handbook: Your Ultimate Cheatsheet
| (Pipe)
By OM PRAMOD
10
The Python Regex Handbook: Your Ultimate Cheatsheet
() (Parentheses)
By OM PRAMOD
11
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
12
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
13
The Python Regex Handbook: Your Ultimate Cheatsheet
{} (Braces)
By OM PRAMOD
14
The Python Regex Handbook: Your Ultimate Cheatsheet
[] (Square Brackets)
By OM PRAMOD
15
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
16
The Python Regex Handbook: Your Ultimate Cheatsheet
 (Backslash)
w
By OM PRAMOD
17
The Python Regex Handbook: Your Ultimate Cheatsheet
W
By OM PRAMOD
18
The Python Regex Handbook: Your Ultimate Cheatsheet
s
By OM PRAMOD
19
The Python Regex Handbook: Your Ultimate Cheatsheet
S
By OM PRAMOD
20
The Python Regex Handbook: Your Ultimate Cheatsheet
d
By OM PRAMOD
21
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
22
The Python Regex Handbook: Your Ultimate Cheatsheet
D
By OM PRAMOD
23
The Python Regex Handbook: Your Ultimate Cheatsheet
b
By OM PRAMOD
24
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
25
The Python Regex Handbook: Your Ultimate Cheatsheet
B
By OM PRAMOD
26
The Python Regex Handbook: Your Ultimate Cheatsheet
A
By OM PRAMOD
27
The Python Regex Handbook: Your Ultimate Cheatsheet
Z
By OM PRAMOD
28
The Python Regex Handbook: Your Ultimate Cheatsheet
n
By OM PRAMOD
29
The Python Regex Handbook: Your Ultimate Cheatsheet
t
By OM PRAMOD
30
The Python Regex Handbook: Your Ultimate Cheatsheet
[a-z]
By OM PRAMOD
31
The Python Regex Handbook: Your Ultimate Cheatsheet
[A-Z]:
[arn]
By OM PRAMOD
32
The Python Regex Handbook: Your Ultimate Cheatsheet
[^arn]
[a-n]
By OM PRAMOD
33
The Python Regex Handbook: Your Ultimate Cheatsheet
[^a-n]
By OM PRAMOD
34
The Python Regex Handbook: Your Ultimate Cheatsheet
[^0-3]
[0123]
By OM PRAMOD
35
The Python Regex Handbook: Your Ultimate Cheatsheet
[0-9]
[0-5][0-9]
By OM PRAMOD
36
The Python Regex Handbook: Your Ultimate Cheatsheet
[a-zA-Z]
By OM PRAMOD
37
The Python Regex Handbook: Your Ultimate Cheatsheet
[a-zA-Z0-9]
{n}
By OM PRAMOD
38
The Python Regex Handbook: Your Ultimate Cheatsheet
{n,}
{,m}:
{n,m}
By OM PRAMOD
39
The Python Regex Handbook: Your Ultimate Cheatsheet
[]
Square
brackets
In regular expressions, square brackets ([]) are used to define a character set, which
is a set of characters you want to match. This can be useful when you want to match
any one character from a specific set of characters.
You can also use square brackets to match any character that is not in a specific set.
This is done by placing a caret (^) at the start of the character set
In addition to individual characters, you can also use a hyphen (-) inside square
brackets to specify a range of characters.
However, if you want to include a hyphen in your character set, you need to place it
at the start or end of the character set. This is because the hyphen is used to denote
a range in regular expressions. Placing it at the start or end ensures it is interpreted
as the literal character - and not as a range specifier.
By OM PRAMOD
40
The Python Regex Handbook: Your Ultimate Cheatsheet
In some cases, you might want to match the square brackets themselves as
characters. This can be done by escaping the square brackets with a backslash ().This
is because square brackets have a special meaning in regular expressions, denoting a
character set. By using a backslash, you’re indicating that you want to match the literal
character and not use its special meaning. For instance, For example, the regular
expression [ will match a single opening square bracket, and ] will match a single
closing square bracket.
. Period
In regular expressions, the dot (.) is a special character that matches any single
character except newline characters(This is an important aspect of regular
expressions to keep in mind when matching across multiple lines.). This means it can
represent any character from the alphabet, numbers, special characters, etc.
By OM PRAMOD
41
The Python Regex Handbook: Your Ultimate Cheatsheet
If you want to match a literal dot (.), you need to escape it using a backslash (). For
example, the regular expression . will match a single dot. This is because inside a
character class, the dot (.) loses its special meaning and matches a literal dot.
^ Caret
In regular expressions, the caret (^) is a special character that has different meanings
depending on its usage. Start of Line or String: When used at the start of a regular
expression, the caret (^) represents the start of a line or a string. For example, the
regular expression ^hello will match any string that starts with the word "hello".
Negation in Character Sets: When used inside square brackets ([]), the caret (^)
negates the set of characters. This means it will match any character that is not in the
set. For example, the regular expression [^abc] will match any character that is not 'a',
'b', or 'c'.
Literal Caret Character: If you want to match the actual caret (^) character, you need
to escape it using a backslash (). For example, the regular expression ^ will match a
single caret.
By OM PRAMOD
42
The Python Regex Handbook: Your Ultimate Cheatsheet
$ Dollar
In regular expressions, the dollar sign ($) is a special character that represents the end
of a line or a string.
* Star
In regular expressions, the asterisk (*) is a special character known as a quantifier that
specifies that the preceding character or group should be matched zero or more
times. This means it can match the preceding character or group any number of times,
including not at all.
If you want to match a literal asterisk (*), you need to escape it using a backslash ().
For example, the regular expression * will match a single asterisk. This is because
inside a character class, the asterisk (*) loses its special meaning and matches a literal
asterisk.
By OM PRAMOD
43
The Python Regex Handbook: Your Ultimate Cheatsheet
+ Plus
In regular expressions, the plus sign (+) is a special character known as a quantifier
that specifies that the preceding character or group should be matched one or more
times. This means it can match the preceding character or group at least once, but
possibly more.
If you want to match a literal plus sign (+), you need to escape it using a backslash ().
For example, the regular expression + will match a single plus sign. This is because
inside a character class, the plus sign (+) loses its special meaning and matches a literal
plus sign. This is an example of how escaping works in regular expressions. Escaping
is used to treat special characters as literal characters.
Inside a character class (denoted by square brackets []), the plus sign + loses its special
meaning and matches a literal plus sign. For example, the regular expression [+] will
match a single plus sign. This is because inside a character class, special characters
lose their special meaning and are treated as literal characters. This is another
important aspect of regular expressions to keep in mind.
By OM PRAMOD
44
The Python Regex Handbook: Your Ultimate Cheatsheet
?
Question
Mark
In regular expressions, the question mark (?) is a special character known as a
quantifier that specifies that the preceding character or group should be matched
zero or one times. This means it can match the preceding character or group either
once or not at all.
If you want to match a literal question mark (?), you need to escape it using a
backslash (). For example, the regular expression ? will match a single question
mark. This is because inside a character class, the question mark (?) loses its special
meaning and matches a literal question mark. Similarly, inside a character class
(denoted by square brackets []), most special characters lose their special meaning
and are treated as literal characters. So, [?] would also match a literal question mark
(?).
In addition to its role as a quantifier, the question mark (?) can also be used in certain
contexts to make a group optional or to apply modifiers to only part of the regular
expression. Optional Grouping: You can use the question mark to make an entire
By OM PRAMOD
45
The Python Regex Handbook: Your Ultimate Cheatsheet
group optional. This is done by surrounding the part of the pattern that should be
optional with parentheses (), and placing a question mark after the closing parenthesis
Modifiers: The question mark can also be used to apply modifiers to only part of the
regular expression. This is done by placing the modifier after a question mark inside
parentheses. In regular expressions, (?i) is a mode modifier that makes the rest of the
pattern case-insensitive. This means that the pattern will match regardless of whether
the characters are in uppercase or lowercase. For example, the pattern (?i) abc will
match abc, ABC, Abc, aBc, abC, ABc, aBC, and AbC. It’s a very useful feature when you
want to match a string regardless of its case. Please note that the ?i should be
enclosed in parentheses like this: (?i).
By OM PRAMOD
46
The Python Regex Handbook: Your Ultimate Cheatsheet
The (?=) syntax in regular expressions is known as a positive lookahead assertion. It is
used to assert that a certain pattern is ahead in the string, but it does not consume
any of the string. This means that the current position in the string remains the same
after the lookahead assertion. Lookahead assertions are particularly useful when you
want to match a pattern only if it's followed by another pattern, but you don't want
to include the second pattern in the match. For example, consider the regular
expression q(?=u)i. This expression will match a 'q' that is followed by a 'u', without
making the 'u' part of the match. The positive lookahead construct is a pair of
parentheses, with the opening parenthesis followed by a question mark and an equals
sign.
{} Braces
In regular expressions, curly braces ({}) are used as quantifiers to specify the exact
number of times a character or group should be matched. They are used in the format
{n}, where n is the exact number of times the preceding character or group should be
matched.
By OM PRAMOD
47
The Python Regex Handbook: Your Ultimate Cheatsheet
If you want to match a literal pair of curly braces ({}), you need to escape them using
a backslash (). For example, the regular expression {} will match a single pair of
curly braces. This is because inside a character class, the curly braces ({}) lose their
special meaning and match a literal pair of curly braces. Similarly, inside a character
class (denoted by square brackets []), most special characters lose their special
meaning and are treated as literal characters. So, [{}] would also match a literal pair
of curly braces ({}).
Curly braces can also be used in the format {n,} to match the preceding character or
group at least n times. For example, the regular expression a{2,} will match "aa",
"aaa", "aaaa", and so on.
the {,m} quantifier in regular expressions specifies that the preceding character or
group should be matched at most m times. Here m is a positive integer. If the
character or group appears more than m times, it will not be a match.
By OM PRAMOD
48
The Python Regex Handbook: Your Ultimate Cheatsheet
Similarly, curly braces can be used in the format {n,m} to match the preceding
character or group at least n times and at most m times. For example, the regular
expression a{2,3} will match "aa", "aaa"
|
Alternatio
n
In regular expressions, the pipe symbol (|) is used as an alternation operator, which
is similar to the logical OR operator. It allows you to match either the pattern before
the pipe or the pattern after the pipe.
() Group
In regular expressions, parentheses (()) are used for grouping and capturing.
Grouping: Parentheses are used to group parts of a regular expression together. This
allows you to apply a quantifier to the entire group or to restrict alternation to part of
the regular expression. Parentheses group parts of the pattern together. This allows
you to apply quantifiers to multiple characters instead of just one. For example, in the
pattern (abc)+, the + applies to the entire string abc, not just the character c.
By OM PRAMOD
49
The Python Regex Handbook: Your Ultimate Cheatsheet
Capturing: Besides grouping part of a regular expression together, parentheses also
create a numbered capturing group. It stores the part of the string matched by the
part of the regular expression inside the parentheses.
By OM PRAMOD
50
The Python Regex Handbook: Your Ultimate Cheatsheet
The (?i) keyword in regular expressions is used to perform case-insensitive matching.
When included in a regular expression, it makes the expression match the target string
regardless of the case of the characters. The (?i) keyword is particularly useful when
you're not sure of the exact casing of the string you're trying to match or when you
want to match multiple variations of a word or phrase. It allows you to write more
flexible and robust regular expressions that can handle different input formats. For
example, the regular expression /python/ would only match strings that contain the
word "python" in lowercase. However, if you add (?i) to the beginning of the
expression, like /(?i)python/, it will match strings that contain "python" in any
combination of uppercase and lowercase letters, such as "Python", "PYTHON", or
"pYThOn".
By OM PRAMOD
51
The Python Regex Handbook: Your Ultimate Cheatsheet
If you want to match parentheses as literal characters in a string, you need to escape
them with a backslash . So, if you want to match a string that contains parentheses,
you would use ( and ) in your regular expression.
 Backslash
In regular expressions, the backslash () is used as an escape character. It allows you
to match special characters that have a specific meaning in regular expressions, such
as . (dot), * (asterisk), + (plus), ? (question mark), ^ (caret), $ (dollar sign), {} (curly
braces), [] (square brackets), () (parentheses), and | (pipe). For instance, if you want
to match a literal asterisk (*), you need to escape it using a backslash (). For example,
the regular expression * will match a single asterisk. Here are some examples:
By OM PRAMOD
52
The Python Regex Handbook: Your Ultimate Cheatsheet
A In regular expressions, the sequence A is a special sequence that matches the start of the string.
It is equivalent to the caret (^) character, which also matches the start of the string. However,
unlike the caret, A does not match the start of a line in a multiline string, it only matches the start
of the entire string.
Z In regular expressions, the sequence Z is a special sequence that matches the end of the string.
It is equivalent to the dollar sign ($) character, which also matches the end of the string. However,
unlike the dollar sign, Z does not match the end of a line in a multiline string, it only matches the
end of the entire string.
b In regular expressions, the sequence b is a special sequence that matches the empty string, but
only at the beginning or end of a word. A word is a set of alphanumeric characters surrounded by
non-alphanumeric characters (such as space).
By OM PRAMOD
53
The Python Regex Handbook: Your Ultimate Cheatsheet
It's important to note that the b sequence always matches the empty string or boundary
between an alphanumeric character and a non-alphanumeric character. For instance, if you are
looking for the word "ssa", using a b special sequence like this "bssab" will not return a match
because non-alphanumeric characters do not border it on both sides.
B In regular expressions, the sequence B is a special sequence that matches the empty string, but
only at positions where one side is a word character and the other side is not a word character. A
word character is a character that can be used to form words. These include alphanumeric
characters (letters and digits) and the underscore character.
By OM PRAMOD
54
The Python Regex Handbook: Your Ultimate Cheatsheet
In regular expressions, the sequence b is a special sequence that matches the empty string, but
only at the beginning or end of a word. A word is a set of alphanumeric characters surrounded by
non-alphanumeric characters (such as space).
d In regular expressions, the sequence d is a special sequence that matches any digit from 0 to 9.
It's equivalent to the character set [0-9].
By OM PRAMOD
55
The Python Regex Handbook: Your Ultimate Cheatsheet
If you want to match a specific number of digits, you can use the d sequence with a quantifier.
For example, the regular expression d{3} will match any sequence of exactly three digits.
D In regular expressions, the sequence D is a special sequence that matches any character that is
not a digit. It's equivalent to the character set [^0-9].
If you want to match a specific number of non-digit characters, you can use the D sequence with
a quantifier. For example, the regular expression D{3} will match any sequence of exactly three
non-digit characters.
By OM PRAMOD
56
The Python Regex Handbook: Your Ultimate Cheatsheet
s In regular expressions, the sequence s is a special sequence that matches any whitespace
character. This includes spaces, tabs, line breaks, and other space-like characters.
S In regular expressions, the sequence S is a special sequence that matches any non-whitespace
character. This includes all characters that are not spaces, tabs, line breaks, and other space-like
characters.
If you want to match a specific number of non-whitespace characters, you can use the S
sequence with a quantifier. For example, the regular expression S{3} will match any sequence of
exactly three non-whitespace characters
By OM PRAMOD
57
The Python Regex Handbook: Your Ultimate Cheatsheet
w In regular expressions, the sequence w is a special sequence that matches any word character.
A word character is a character that can be used to form words. These include alphanumeric
characters (letters and digits) and the underscore character.
If you want to match a specific number of word characters, you can use the w sequence with a
quantifier. For example, the regular expression w{3} will match any sequence of exactly three
word characters.
By OM PRAMOD
58
The Python Regex Handbook: Your Ultimate Cheatsheet
W In regular expressions, the sequence W is a special sequence that matches any non-word
character. A non-word character is a character that cannot be used to form words. These include
all characters that are not alphanumeric (letters and digits) and not underscores.
By OM PRAMOD
59
The Python Regex Handbook: Your Ultimate Cheatsheet
Python RegEx Expressions Functions
re.search(pattern,
string)
By OM PRAMOD
60
The Python Regex Handbook: Your Ultimate Cheatsheet
re.findall(pattern,
string)
By OM PRAMOD
61
The Python Regex Handbook: Your Ultimate Cheatsheet
re.match(pattern,
string)
By OM PRAMOD
62
The Python Regex Handbook: Your Ultimate Cheatsheet
re.split(pattern,
string)
By OM PRAMOD
63
The Python Regex Handbook: Your Ultimate Cheatsheet
re.fullmatch(pattern,
string)
By OM PRAMOD
64
The Python Regex Handbook: Your Ultimate Cheatsheet
re.finditer(pattern,
string)
By OM PRAMOD
65
The Python Regex Handbook: Your Ultimate Cheatsheet
re.sub(pattern,
replacement, string)
By OM PRAMOD
66
The Python Regex Handbook: Your Ultimate Cheatsheet
re.escape(string)
By OM PRAMOD
67
The Python Regex Handbook: Your Ultimate Cheatsheet
re.subn()
By OM PRAMOD
68
The Python Regex Handbook: Your Ultimate Cheatsheet
re.VERBOSE
By OM PRAMOD
69
The Python Regex Handbook: Your Ultimate Cheatsheet
re.MULTILINE
By OM PRAMOD
70
The Python Regex Handbook: Your Ultimate Cheatsheet
By OM PRAMOD
71
The Python Regex Handbook: Your Ultimate Cheatsheet
SUMMARY
By OM PRAMOD
72
The Python Regex Handbook: Your Ultimate Cheatsheet
buymeacoffee.com/ompramod
https://medium.com/@ompramod9921

More Related Content

What's hot

PTE EXAM
PTE EXAMPTE EXAM
PTE EXAM
ptemocktest.com
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
Haim Michael
 
Functional Programming in Python
Functional Programming in PythonFunctional Programming in Python
Functional Programming in Python
Haim Michael
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
Martin McBride
 
312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf
312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf
312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf
Anabela Sousa
 
Hsk1 l1
Hsk1 l1Hsk1 l1
Hsk1 l1
嵄 陈
 
Hsk1 l10
Hsk1 l10Hsk1 l10
Hsk1 l10
rahman911452
 
Top 100 Python Interview Questions And Answers
Top 100 Python Interview Questions And AnswersTop 100 Python Interview Questions And Answers
Top 100 Python Interview Questions And Answers
ProBytes
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
Praveen M Jigajinni
 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++
Ilio Catallo
 
Speaking skills in English
Speaking skills in EnglishSpeaking skills in English
Speaking skills in English
SalmanHameedJoyia
 
Python basics
Python basicsPython basics
Python basics
Jyoti shukla
 
Fail2ban - the system security for green hand -on linux os
Fail2ban  - the system security  for green hand -on linux osFail2ban  - the system security  for green hand -on linux os
Fail2ban - the system security for green hand -on linux os
Samina Fu (Shan Jung Fu)
 
Using SketchUp with openFoam
Using SketchUp with openFoamUsing SketchUp with openFoam
Using SketchUp with openFoam
Julien de Charentenay
 
Advantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonAdvantages of Python Learning | Why Python
Advantages of Python Learning | Why Python
EvoletTechnologiesCo
 

What's hot (15)

PTE EXAM
PTE EXAMPTE EXAM
PTE EXAM
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
 
Functional Programming in Python
Functional Programming in PythonFunctional Programming in Python
Functional Programming in Python
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf
312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf
312420443 collins-practice-tests-for-yle-movers-teacher-s-guide-pdf
 
Hsk1 l1
Hsk1 l1Hsk1 l1
Hsk1 l1
 
Hsk1 l10
Hsk1 l10Hsk1 l10
Hsk1 l10
 
Top 100 Python Interview Questions And Answers
Top 100 Python Interview Questions And AnswersTop 100 Python Interview Questions And Answers
Top 100 Python Interview Questions And Answers
 
11 Unit 1 Chapter 02 Python Fundamentals
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
 
Gestione della memoria in C++
Gestione della memoria in C++Gestione della memoria in C++
Gestione della memoria in C++
 
Speaking skills in English
Speaking skills in EnglishSpeaking skills in English
Speaking skills in English
 
Python basics
Python basicsPython basics
Python basics
 
Fail2ban - the system security for green hand -on linux os
Fail2ban  - the system security  for green hand -on linux osFail2ban  - the system security  for green hand -on linux os
Fail2ban - the system security for green hand -on linux os
 
Using SketchUp with openFoam
Using SketchUp with openFoamUsing SketchUp with openFoam
Using SketchUp with openFoam
 
Advantages of Python Learning | Why Python
Advantages of Python Learning | Why PythonAdvantages of Python Learning | Why Python
Advantages of Python Learning | Why Python
 

Similar to RegEx Book.pdf

Regular expressions
Regular expressionsRegular expressions
Regular expressions
Raghu nath
 
Introduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RIntroduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_R
Hellen Gakuruh
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
Max Kleiner
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
Jun Shimizu
 
Andrei's Regex Clinic
Andrei's Regex ClinicAndrei's Regex Clinic
Andrei's Regex Clinic
Andrei Zmievski
 
Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5
bilcorry
 
Chapter 3: Introduction to Regular Expression
Chapter 3: Introduction to Regular ExpressionChapter 3: Introduction to Regular Expression
Chapter 3: Introduction to Regular Expression
azzamhadeel89
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
Logan Palanisamy
 
Looking for Patterns
Looking for PatternsLooking for Patterns
Looking for Patterns
Keith Wright
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
Satya Narayana
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Thomas Langston
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
Mahzad Zahedi
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
Mukesh Tekwani
 
Python - Lecture 7
Python - Lecture 7Python - Lecture 7
Python - Lecture 7
Ravi Kiran Khareedi
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
mussawir20
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressions
Yamagata Europe
 
Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014
Sandy Smith
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
Ben Brumfield
 
Grep Introduction
Grep IntroductionGrep Introduction
Grep Introduction
Anthony Magee
 

Similar to RegEx Book.pdf (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Introduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_RIntroduction_to_Regular_Expressions_in_R
Introduction_to_Regular_Expressions_in_R
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
 
Andrei's Regex Clinic
Andrei's Regex ClinicAndrei's Regex Clinic
Andrei's Regex Clinic
 
Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5
 
Chapter 3: Introduction to Regular Expression
Chapter 3: Introduction to Regular ExpressionChapter 3: Introduction to Regular Expression
Chapter 3: Introduction to Regular Expression
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
Looking for Patterns
Looking for PatternsLooking for Patterns
Looking for Patterns
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
Python - Lecture 7
Python - Lecture 7Python - Lecture 7
Python - Lecture 7
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressions
 
Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Grep Introduction
Grep IntroductionGrep Introduction
Grep Introduction
 

Recently uploaded

2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt
abdatawakjira
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
P5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civilP5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civil
AnasAhmadNoor
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
upoux
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
sachin chaurasia
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Transcat
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
b0754201
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
AlvianRamadhani5
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
cannyengineerings
 

Recently uploaded (20)

2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt2. protection of river banks and bed erosion protection works.ppt
2. protection of river banks and bed erosion protection works.ppt
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
P5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civilP5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civil
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
一比一原版(uofo毕业证书)美国俄勒冈大学毕业证如何办理
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
Mechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineeringMechatronics material . Mechanical engineering
Mechatronics material . Mechanical engineering
 
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
Tools & Techniques for Commissioning and Maintaining PV Systems W-Animations ...
 
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptxSENTIMENT ANALYSIS ON PPT AND Project template_.pptx
SENTIMENT ANALYSIS ON PPT AND Project template_.pptx
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...Pressure Relief valve used in flow line to release the over pressure at our d...
Pressure Relief valve used in flow line to release the over pressure at our d...
 

RegEx Book.pdf

  • 1. Your Ultimate Cheatsheet AIML Enthusiast Om Pramod
  • 2. By OM PRAMOD 1 The Python Regex Handbook: Your Ultimate Cheatsheet Period (.)
  • 3. By OM PRAMOD 2 The Python Regex Handbook: Your Ultimate Cheatsheet * (Asterisk)
  • 4. By OM PRAMOD 3 The Python Regex Handbook: Your Ultimate Cheatsheet Caret (^)
  • 5. By OM PRAMOD 4 The Python Regex Handbook: Your Ultimate Cheatsheet $ (Dollar)
  • 6. By OM PRAMOD 5 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 7. By OM PRAMOD 6 The Python Regex Handbook: Your Ultimate Cheatsheet + (Plus)
  • 8. By OM PRAMOD 7 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 9. By OM PRAMOD 8 The Python Regex Handbook: Your Ultimate Cheatsheet ? (Question Mark)
  • 10. By OM PRAMOD 9 The Python Regex Handbook: Your Ultimate Cheatsheet | (Pipe)
  • 11. By OM PRAMOD 10 The Python Regex Handbook: Your Ultimate Cheatsheet () (Parentheses)
  • 12. By OM PRAMOD 11 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 13. By OM PRAMOD 12 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 14. By OM PRAMOD 13 The Python Regex Handbook: Your Ultimate Cheatsheet {} (Braces)
  • 15. By OM PRAMOD 14 The Python Regex Handbook: Your Ultimate Cheatsheet [] (Square Brackets)
  • 16. By OM PRAMOD 15 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 17. By OM PRAMOD 16 The Python Regex Handbook: Your Ultimate Cheatsheet (Backslash) w
  • 18. By OM PRAMOD 17 The Python Regex Handbook: Your Ultimate Cheatsheet W
  • 19. By OM PRAMOD 18 The Python Regex Handbook: Your Ultimate Cheatsheet s
  • 20. By OM PRAMOD 19 The Python Regex Handbook: Your Ultimate Cheatsheet S
  • 21. By OM PRAMOD 20 The Python Regex Handbook: Your Ultimate Cheatsheet d
  • 22. By OM PRAMOD 21 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 23. By OM PRAMOD 22 The Python Regex Handbook: Your Ultimate Cheatsheet D
  • 24. By OM PRAMOD 23 The Python Regex Handbook: Your Ultimate Cheatsheet b
  • 25. By OM PRAMOD 24 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 26. By OM PRAMOD 25 The Python Regex Handbook: Your Ultimate Cheatsheet B
  • 27. By OM PRAMOD 26 The Python Regex Handbook: Your Ultimate Cheatsheet A
  • 28. By OM PRAMOD 27 The Python Regex Handbook: Your Ultimate Cheatsheet Z
  • 29. By OM PRAMOD 28 The Python Regex Handbook: Your Ultimate Cheatsheet n
  • 30. By OM PRAMOD 29 The Python Regex Handbook: Your Ultimate Cheatsheet t
  • 31. By OM PRAMOD 30 The Python Regex Handbook: Your Ultimate Cheatsheet [a-z]
  • 32. By OM PRAMOD 31 The Python Regex Handbook: Your Ultimate Cheatsheet [A-Z]: [arn]
  • 33. By OM PRAMOD 32 The Python Regex Handbook: Your Ultimate Cheatsheet [^arn] [a-n]
  • 34. By OM PRAMOD 33 The Python Regex Handbook: Your Ultimate Cheatsheet [^a-n]
  • 35. By OM PRAMOD 34 The Python Regex Handbook: Your Ultimate Cheatsheet [^0-3] [0123]
  • 36. By OM PRAMOD 35 The Python Regex Handbook: Your Ultimate Cheatsheet [0-9] [0-5][0-9]
  • 37. By OM PRAMOD 36 The Python Regex Handbook: Your Ultimate Cheatsheet [a-zA-Z]
  • 38. By OM PRAMOD 37 The Python Regex Handbook: Your Ultimate Cheatsheet [a-zA-Z0-9] {n}
  • 39. By OM PRAMOD 38 The Python Regex Handbook: Your Ultimate Cheatsheet {n,} {,m}: {n,m}
  • 40. By OM PRAMOD 39 The Python Regex Handbook: Your Ultimate Cheatsheet [] Square brackets In regular expressions, square brackets ([]) are used to define a character set, which is a set of characters you want to match. This can be useful when you want to match any one character from a specific set of characters. You can also use square brackets to match any character that is not in a specific set. This is done by placing a caret (^) at the start of the character set In addition to individual characters, you can also use a hyphen (-) inside square brackets to specify a range of characters. However, if you want to include a hyphen in your character set, you need to place it at the start or end of the character set. This is because the hyphen is used to denote a range in regular expressions. Placing it at the start or end ensures it is interpreted as the literal character - and not as a range specifier.
  • 41. By OM PRAMOD 40 The Python Regex Handbook: Your Ultimate Cheatsheet In some cases, you might want to match the square brackets themselves as characters. This can be done by escaping the square brackets with a backslash ().This is because square brackets have a special meaning in regular expressions, denoting a character set. By using a backslash, you’re indicating that you want to match the literal character and not use its special meaning. For instance, For example, the regular expression [ will match a single opening square bracket, and ] will match a single closing square bracket. . Period In regular expressions, the dot (.) is a special character that matches any single character except newline characters(This is an important aspect of regular expressions to keep in mind when matching across multiple lines.). This means it can represent any character from the alphabet, numbers, special characters, etc.
  • 42. By OM PRAMOD 41 The Python Regex Handbook: Your Ultimate Cheatsheet If you want to match a literal dot (.), you need to escape it using a backslash (). For example, the regular expression . will match a single dot. This is because inside a character class, the dot (.) loses its special meaning and matches a literal dot. ^ Caret In regular expressions, the caret (^) is a special character that has different meanings depending on its usage. Start of Line or String: When used at the start of a regular expression, the caret (^) represents the start of a line or a string. For example, the regular expression ^hello will match any string that starts with the word "hello". Negation in Character Sets: When used inside square brackets ([]), the caret (^) negates the set of characters. This means it will match any character that is not in the set. For example, the regular expression [^abc] will match any character that is not 'a', 'b', or 'c'. Literal Caret Character: If you want to match the actual caret (^) character, you need to escape it using a backslash (). For example, the regular expression ^ will match a single caret.
  • 43. By OM PRAMOD 42 The Python Regex Handbook: Your Ultimate Cheatsheet $ Dollar In regular expressions, the dollar sign ($) is a special character that represents the end of a line or a string. * Star In regular expressions, the asterisk (*) is a special character known as a quantifier that specifies that the preceding character or group should be matched zero or more times. This means it can match the preceding character or group any number of times, including not at all. If you want to match a literal asterisk (*), you need to escape it using a backslash (). For example, the regular expression * will match a single asterisk. This is because inside a character class, the asterisk (*) loses its special meaning and matches a literal asterisk.
  • 44. By OM PRAMOD 43 The Python Regex Handbook: Your Ultimate Cheatsheet + Plus In regular expressions, the plus sign (+) is a special character known as a quantifier that specifies that the preceding character or group should be matched one or more times. This means it can match the preceding character or group at least once, but possibly more. If you want to match a literal plus sign (+), you need to escape it using a backslash (). For example, the regular expression + will match a single plus sign. This is because inside a character class, the plus sign (+) loses its special meaning and matches a literal plus sign. This is an example of how escaping works in regular expressions. Escaping is used to treat special characters as literal characters. Inside a character class (denoted by square brackets []), the plus sign + loses its special meaning and matches a literal plus sign. For example, the regular expression [+] will match a single plus sign. This is because inside a character class, special characters lose their special meaning and are treated as literal characters. This is another important aspect of regular expressions to keep in mind.
  • 45. By OM PRAMOD 44 The Python Regex Handbook: Your Ultimate Cheatsheet ? Question Mark In regular expressions, the question mark (?) is a special character known as a quantifier that specifies that the preceding character or group should be matched zero or one times. This means it can match the preceding character or group either once or not at all. If you want to match a literal question mark (?), you need to escape it using a backslash (). For example, the regular expression ? will match a single question mark. This is because inside a character class, the question mark (?) loses its special meaning and matches a literal question mark. Similarly, inside a character class (denoted by square brackets []), most special characters lose their special meaning and are treated as literal characters. So, [?] would also match a literal question mark (?). In addition to its role as a quantifier, the question mark (?) can also be used in certain contexts to make a group optional or to apply modifiers to only part of the regular expression. Optional Grouping: You can use the question mark to make an entire
  • 46. By OM PRAMOD 45 The Python Regex Handbook: Your Ultimate Cheatsheet group optional. This is done by surrounding the part of the pattern that should be optional with parentheses (), and placing a question mark after the closing parenthesis Modifiers: The question mark can also be used to apply modifiers to only part of the regular expression. This is done by placing the modifier after a question mark inside parentheses. In regular expressions, (?i) is a mode modifier that makes the rest of the pattern case-insensitive. This means that the pattern will match regardless of whether the characters are in uppercase or lowercase. For example, the pattern (?i) abc will match abc, ABC, Abc, aBc, abC, ABc, aBC, and AbC. It’s a very useful feature when you want to match a string regardless of its case. Please note that the ?i should be enclosed in parentheses like this: (?i).
  • 47. By OM PRAMOD 46 The Python Regex Handbook: Your Ultimate Cheatsheet The (?=) syntax in regular expressions is known as a positive lookahead assertion. It is used to assert that a certain pattern is ahead in the string, but it does not consume any of the string. This means that the current position in the string remains the same after the lookahead assertion. Lookahead assertions are particularly useful when you want to match a pattern only if it's followed by another pattern, but you don't want to include the second pattern in the match. For example, consider the regular expression q(?=u)i. This expression will match a 'q' that is followed by a 'u', without making the 'u' part of the match. The positive lookahead construct is a pair of parentheses, with the opening parenthesis followed by a question mark and an equals sign. {} Braces In regular expressions, curly braces ({}) are used as quantifiers to specify the exact number of times a character or group should be matched. They are used in the format {n}, where n is the exact number of times the preceding character or group should be matched.
  • 48. By OM PRAMOD 47 The Python Regex Handbook: Your Ultimate Cheatsheet If you want to match a literal pair of curly braces ({}), you need to escape them using a backslash (). For example, the regular expression {} will match a single pair of curly braces. This is because inside a character class, the curly braces ({}) lose their special meaning and match a literal pair of curly braces. Similarly, inside a character class (denoted by square brackets []), most special characters lose their special meaning and are treated as literal characters. So, [{}] would also match a literal pair of curly braces ({}). Curly braces can also be used in the format {n,} to match the preceding character or group at least n times. For example, the regular expression a{2,} will match "aa", "aaa", "aaaa", and so on. the {,m} quantifier in regular expressions specifies that the preceding character or group should be matched at most m times. Here m is a positive integer. If the character or group appears more than m times, it will not be a match.
  • 49. By OM PRAMOD 48 The Python Regex Handbook: Your Ultimate Cheatsheet Similarly, curly braces can be used in the format {n,m} to match the preceding character or group at least n times and at most m times. For example, the regular expression a{2,3} will match "aa", "aaa" | Alternatio n In regular expressions, the pipe symbol (|) is used as an alternation operator, which is similar to the logical OR operator. It allows you to match either the pattern before the pipe or the pattern after the pipe. () Group In regular expressions, parentheses (()) are used for grouping and capturing. Grouping: Parentheses are used to group parts of a regular expression together. This allows you to apply a quantifier to the entire group or to restrict alternation to part of the regular expression. Parentheses group parts of the pattern together. This allows you to apply quantifiers to multiple characters instead of just one. For example, in the pattern (abc)+, the + applies to the entire string abc, not just the character c.
  • 50. By OM PRAMOD 49 The Python Regex Handbook: Your Ultimate Cheatsheet Capturing: Besides grouping part of a regular expression together, parentheses also create a numbered capturing group. It stores the part of the string matched by the part of the regular expression inside the parentheses.
  • 51. By OM PRAMOD 50 The Python Regex Handbook: Your Ultimate Cheatsheet The (?i) keyword in regular expressions is used to perform case-insensitive matching. When included in a regular expression, it makes the expression match the target string regardless of the case of the characters. The (?i) keyword is particularly useful when you're not sure of the exact casing of the string you're trying to match or when you want to match multiple variations of a word or phrase. It allows you to write more flexible and robust regular expressions that can handle different input formats. For example, the regular expression /python/ would only match strings that contain the word "python" in lowercase. However, if you add (?i) to the beginning of the expression, like /(?i)python/, it will match strings that contain "python" in any combination of uppercase and lowercase letters, such as "Python", "PYTHON", or "pYThOn".
  • 52. By OM PRAMOD 51 The Python Regex Handbook: Your Ultimate Cheatsheet If you want to match parentheses as literal characters in a string, you need to escape them with a backslash . So, if you want to match a string that contains parentheses, you would use ( and ) in your regular expression. Backslash In regular expressions, the backslash () is used as an escape character. It allows you to match special characters that have a specific meaning in regular expressions, such as . (dot), * (asterisk), + (plus), ? (question mark), ^ (caret), $ (dollar sign), {} (curly braces), [] (square brackets), () (parentheses), and | (pipe). For instance, if you want to match a literal asterisk (*), you need to escape it using a backslash (). For example, the regular expression * will match a single asterisk. Here are some examples:
  • 53. By OM PRAMOD 52 The Python Regex Handbook: Your Ultimate Cheatsheet A In regular expressions, the sequence A is a special sequence that matches the start of the string. It is equivalent to the caret (^) character, which also matches the start of the string. However, unlike the caret, A does not match the start of a line in a multiline string, it only matches the start of the entire string. Z In regular expressions, the sequence Z is a special sequence that matches the end of the string. It is equivalent to the dollar sign ($) character, which also matches the end of the string. However, unlike the dollar sign, Z does not match the end of a line in a multiline string, it only matches the end of the entire string. b In regular expressions, the sequence b is a special sequence that matches the empty string, but only at the beginning or end of a word. A word is a set of alphanumeric characters surrounded by non-alphanumeric characters (such as space).
  • 54. By OM PRAMOD 53 The Python Regex Handbook: Your Ultimate Cheatsheet It's important to note that the b sequence always matches the empty string or boundary between an alphanumeric character and a non-alphanumeric character. For instance, if you are looking for the word "ssa", using a b special sequence like this "bssab" will not return a match because non-alphanumeric characters do not border it on both sides. B In regular expressions, the sequence B is a special sequence that matches the empty string, but only at positions where one side is a word character and the other side is not a word character. A word character is a character that can be used to form words. These include alphanumeric characters (letters and digits) and the underscore character.
  • 55. By OM PRAMOD 54 The Python Regex Handbook: Your Ultimate Cheatsheet In regular expressions, the sequence b is a special sequence that matches the empty string, but only at the beginning or end of a word. A word is a set of alphanumeric characters surrounded by non-alphanumeric characters (such as space). d In regular expressions, the sequence d is a special sequence that matches any digit from 0 to 9. It's equivalent to the character set [0-9].
  • 56. By OM PRAMOD 55 The Python Regex Handbook: Your Ultimate Cheatsheet If you want to match a specific number of digits, you can use the d sequence with a quantifier. For example, the regular expression d{3} will match any sequence of exactly three digits. D In regular expressions, the sequence D is a special sequence that matches any character that is not a digit. It's equivalent to the character set [^0-9]. If you want to match a specific number of non-digit characters, you can use the D sequence with a quantifier. For example, the regular expression D{3} will match any sequence of exactly three non-digit characters.
  • 57. By OM PRAMOD 56 The Python Regex Handbook: Your Ultimate Cheatsheet s In regular expressions, the sequence s is a special sequence that matches any whitespace character. This includes spaces, tabs, line breaks, and other space-like characters. S In regular expressions, the sequence S is a special sequence that matches any non-whitespace character. This includes all characters that are not spaces, tabs, line breaks, and other space-like characters. If you want to match a specific number of non-whitespace characters, you can use the S sequence with a quantifier. For example, the regular expression S{3} will match any sequence of exactly three non-whitespace characters
  • 58. By OM PRAMOD 57 The Python Regex Handbook: Your Ultimate Cheatsheet w In regular expressions, the sequence w is a special sequence that matches any word character. A word character is a character that can be used to form words. These include alphanumeric characters (letters and digits) and the underscore character. If you want to match a specific number of word characters, you can use the w sequence with a quantifier. For example, the regular expression w{3} will match any sequence of exactly three word characters.
  • 59. By OM PRAMOD 58 The Python Regex Handbook: Your Ultimate Cheatsheet W In regular expressions, the sequence W is a special sequence that matches any non-word character. A non-word character is a character that cannot be used to form words. These include all characters that are not alphanumeric (letters and digits) and not underscores.
  • 60. By OM PRAMOD 59 The Python Regex Handbook: Your Ultimate Cheatsheet Python RegEx Expressions Functions re.search(pattern, string)
  • 61. By OM PRAMOD 60 The Python Regex Handbook: Your Ultimate Cheatsheet re.findall(pattern, string)
  • 62. By OM PRAMOD 61 The Python Regex Handbook: Your Ultimate Cheatsheet re.match(pattern, string)
  • 63. By OM PRAMOD 62 The Python Regex Handbook: Your Ultimate Cheatsheet re.split(pattern, string)
  • 64. By OM PRAMOD 63 The Python Regex Handbook: Your Ultimate Cheatsheet re.fullmatch(pattern, string)
  • 65. By OM PRAMOD 64 The Python Regex Handbook: Your Ultimate Cheatsheet re.finditer(pattern, string)
  • 66. By OM PRAMOD 65 The Python Regex Handbook: Your Ultimate Cheatsheet re.sub(pattern, replacement, string)
  • 67. By OM PRAMOD 66 The Python Regex Handbook: Your Ultimate Cheatsheet re.escape(string)
  • 68. By OM PRAMOD 67 The Python Regex Handbook: Your Ultimate Cheatsheet re.subn()
  • 69. By OM PRAMOD 68 The Python Regex Handbook: Your Ultimate Cheatsheet re.VERBOSE
  • 70. By OM PRAMOD 69 The Python Regex Handbook: Your Ultimate Cheatsheet re.MULTILINE
  • 71. By OM PRAMOD 70 The Python Regex Handbook: Your Ultimate Cheatsheet
  • 72. By OM PRAMOD 71 The Python Regex Handbook: Your Ultimate Cheatsheet SUMMARY
  • 73. By OM PRAMOD 72 The Python Regex Handbook: Your Ultimate Cheatsheet