© Copyright 2020. All rights reserved.
Regular Expressions
REGULAR EXPRESSIONS
In computing, a regular expression, also referred to as
"regex" or "regexp", provides a concise and flexible
means for matching strings of text, such as particular
characters, words, or patterns of characters. A regular
expression is written in a formal language that can be
interpreted by a regular expression processor.
Regular Expressions Quick Guide
^ Matches the beginning of a line
$ Matches the end of the line
. Matches any character
s Matches whitespace
S Matches any non-whitespace character
* Repeats a character zero or more times
*? Repeats a character zero or more times (non-greedy)
Regular Expressions Quick Guide
+ Repeats a character one or more times
+? Repeats a character one or more times (non-greedy)
[aeiou] Matches a single character in the listed set
( Indicates where string extraction is to start
) Indicates where string extraction is to end
[^XYZ] Matches a single character not in the listed set
[a-z0-9] The set of characters can include a range
 backslash (or escape character) quotes the character after it, both
special and ordinary.
Regular Expressions Quick Guide
$ The dollar sign at the end of a regular expression signifies
the end of a line, and, therefore, any character immediately
before it must be located at the end of the string.
d Digit
D Non-Digit
w word
W not word
Example in java
Pattern p = Pattern.compile("colou?r");
Matcher m = p.matcher("The color green");
m.find(); // returns true
m.start(); // returns 4
m.end(); // returns 9
m = p.matcher("abc");
m.find(); // returns false
Example in Python
# Python
p = re.compile("colou?r")
m = p.search("The color green")
m.start() # returns 4
m = p.search("abc") # returns None
The Regular Expression Module
• Before you can use regular expressions in your program,
you must import the library using "import re"
• You can use re.search() to see if a string matches a regular
expression similar to using the find() method for strings
• You can use re.findall() extract portions of a string that
match your regular expression similar to a combination of
find() and slicing: var[5:10]
Wild Card Characters
• The dot character matches any character
• If you add the asterisk character, the character is "any number of times"
X-Sieve: CMU Sieve 2.3
X-DSPAM-Result: Innocent
X-DSPAM-Confidence: 0.8475
X-Content-Type-Message-Body: text/plain
^X.*:
Wild Card Characters
• The dot character matches any character
• If you add the asterisk character, the character is "any
number of times"
X-Sieve: CMU Sieve 2.3
X-DSPAM-Result: Innocent
X-DSPAM-Confidence: 0.8475
X-Content-Type-Message-Body: text/plain
^X.*:
Match the start of the line Many times
Match any character
Matching & Extracting Data
• The re.search() returns a True/False depending on whether
the string matches the regular expression
• If we want the matching strings to be extracted, we use
re.findall()
>>> import re
>>> x = 'My 2 favorite numbers are 19 and 42'
>>> y = re.findall('[0-9]+',x)
>>> print y
['2', '19', '42']
[0-9]+
One or more digits
Re.match vs re.search
There is a difference between the use of both functions. Both return
the first match of a substring found in the string,
but re.match() searches only from the beginning of the string and
return match object if found. But if a match of substring is found
somewhere in the middle of the string, it returns none.
While re.search() searches for the whole string even if the string
contains multi-lines and tries to find a match of the substring in all
the lines of string.
Regular_Expressions.pptx
References
• Regular expression tester:
https://regex101.com/
• URLs to refer:
https://www.regular-expressions.info/modifiers.html
https://docs.python.org/3.6/library/re.html#re.I
http://evc-cit.info/comsc020/python-regex-tutorial/
https://www.w3schools.com/jsref/jsref_obj_regexp.asp
• Regex questions with solution (Pre-requisite: Anaconda must be installed in your machine to run
jupyter notebook):
• Other important documents to refer:
Regex Notes
Regex cheatsheet
© Copyright 2021. All rights reserved.
THANK YOU

More Related Content

PDF
Python (regular expression)
PDF
regular-expression.pdf
PPTX
Regular Expressions
DOCX
Python - Regular Expressions
PPTX
regex.pptx
PPTX
unit-4 regular expression.pptx
PPTX
Pythonlearn-11-Regex.pptx
PPTX
Regular expressions using Python
Python (regular expression)
regular-expression.pdf
Regular Expressions
Python - Regular Expressions
regex.pptx
unit-4 regular expression.pptx
Pythonlearn-11-Regex.pptx
Regular expressions using Python

Similar to Regular_Expressions.pptx (20)

PDF
Python - Lecture 7
PPT
Adv. python regular expression by Rj
PDF
Regular expressions
PPTX
Common regex pp functions wweweewwt.pptx
PDF
Python Regular Expressions
ODP
OISF: Regular Expressions (Regex) Overview
ODP
DerbyCon 7.0 Legacy: Regular Expressions (Regex) Overview
PDF
Module 3 - Regular Expressions, Dictionaries.pdf
PDF
Regex startup
PDF
Python : Regular expressions
PPTX
Regular Expressions Boot Camp
PPT
RegEx : Expressions and Parsing Examples
PPTX
Python advanced 2. regular expression in python
PPT
Regular Expressions grep and egrep
PDF
Regular expression in python for students
PDF
A3 sec -_regular_expressions
PPT
Chapter-three automata and complexity theory.ppt
ODP
CiNPA Security SIG - Regex Presentation
PPTX
Regular Expression (Regex) Fundamentals
PPT
Regular expressions
Python - Lecture 7
Adv. python regular expression by Rj
Regular expressions
Common regex pp functions wweweewwt.pptx
Python Regular Expressions
OISF: Regular Expressions (Regex) Overview
DerbyCon 7.0 Legacy: Regular Expressions (Regex) Overview
Module 3 - Regular Expressions, Dictionaries.pdf
Regex startup
Python : Regular expressions
Regular Expressions Boot Camp
RegEx : Expressions and Parsing Examples
Python advanced 2. regular expression in python
Regular Expressions grep and egrep
Regular expression in python for students
A3 sec -_regular_expressions
Chapter-three automata and complexity theory.ppt
CiNPA Security SIG - Regex Presentation
Regular Expression (Regex) Fundamentals
Regular expressions
Ad

Recently uploaded (20)

PPTX
Tech Workshop Escape Room Tech Workshop
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
AI Guide for Business Growth - Arna Softech
PDF
Guide to Food Delivery App Development.pdf
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PPTX
Matchmaking for JVMs: How to Pick the Perfect GC Partner
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
BoxLang Dynamic AWS Lambda - Japan Edition
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
CNN LeNet5 Architecture: Neural Networks
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
DOC
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
PPTX
Introduction to Windows Operating System
PDF
E-Commerce Website Development Companyin india
PPTX
Cybersecurity: Protecting the Digital World
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Download Adobe Photoshop Crack 2025 Free
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
Tech Workshop Escape Room Tech Workshop
iTop VPN Crack Latest Version Full Key 2025
AI Guide for Business Growth - Arna Softech
Guide to Food Delivery App Development.pdf
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
Matchmaking for JVMs: How to Pick the Perfect GC Partner
Salesforce Agentforce AI Implementation.pdf
BoxLang Dynamic AWS Lambda - Japan Edition
Wondershare Recoverit Full Crack New Version (Latest 2025)
How Tridens DevSecOps Ensures Compliance, Security, and Agility
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
CNN LeNet5 Architecture: Neural Networks
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
UTEP毕业证学历认证,宾夕法尼亚克拉里恩大学毕业证未毕业
Introduction to Windows Operating System
E-Commerce Website Development Companyin india
Cybersecurity: Protecting the Digital World
"Secure File Sharing Solutions on AWS".pptx
Download Adobe Photoshop Crack 2025 Free
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
Ad

Regular_Expressions.pptx

  • 1. © Copyright 2020. All rights reserved. Regular Expressions
  • 2. REGULAR EXPRESSIONS In computing, a regular expression, also referred to as "regex" or "regexp", provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. A regular expression is written in a formal language that can be interpreted by a regular expression processor.
  • 3. Regular Expressions Quick Guide ^ Matches the beginning of a line $ Matches the end of the line . Matches any character s Matches whitespace S Matches any non-whitespace character * Repeats a character zero or more times *? Repeats a character zero or more times (non-greedy)
  • 4. Regular Expressions Quick Guide + Repeats a character one or more times +? Repeats a character one or more times (non-greedy) [aeiou] Matches a single character in the listed set ( Indicates where string extraction is to start ) Indicates where string extraction is to end [^XYZ] Matches a single character not in the listed set [a-z0-9] The set of characters can include a range backslash (or escape character) quotes the character after it, both special and ordinary.
  • 5. Regular Expressions Quick Guide $ The dollar sign at the end of a regular expression signifies the end of a line, and, therefore, any character immediately before it must be located at the end of the string. d Digit D Non-Digit w word W not word
  • 6. Example in java Pattern p = Pattern.compile("colou?r"); Matcher m = p.matcher("The color green"); m.find(); // returns true m.start(); // returns 4 m.end(); // returns 9 m = p.matcher("abc"); m.find(); // returns false
  • 7. Example in Python # Python p = re.compile("colou?r") m = p.search("The color green") m.start() # returns 4 m = p.search("abc") # returns None
  • 8. The Regular Expression Module • Before you can use regular expressions in your program, you must import the library using "import re" • You can use re.search() to see if a string matches a regular expression similar to using the find() method for strings • You can use re.findall() extract portions of a string that match your regular expression similar to a combination of find() and slicing: var[5:10]
  • 9. Wild Card Characters • The dot character matches any character • If you add the asterisk character, the character is "any number of times" X-Sieve: CMU Sieve 2.3 X-DSPAM-Result: Innocent X-DSPAM-Confidence: 0.8475 X-Content-Type-Message-Body: text/plain ^X.*:
  • 10. Wild Card Characters • The dot character matches any character • If you add the asterisk character, the character is "any number of times" X-Sieve: CMU Sieve 2.3 X-DSPAM-Result: Innocent X-DSPAM-Confidence: 0.8475 X-Content-Type-Message-Body: text/plain ^X.*: Match the start of the line Many times Match any character
  • 11. Matching & Extracting Data • The re.search() returns a True/False depending on whether the string matches the regular expression • If we want the matching strings to be extracted, we use re.findall() >>> import re >>> x = 'My 2 favorite numbers are 19 and 42' >>> y = re.findall('[0-9]+',x) >>> print y ['2', '19', '42'] [0-9]+ One or more digits
  • 12. Re.match vs re.search There is a difference between the use of both functions. Both return the first match of a substring found in the string, but re.match() searches only from the beginning of the string and return match object if found. But if a match of substring is found somewhere in the middle of the string, it returns none. While re.search() searches for the whole string even if the string contains multi-lines and tries to find a match of the substring in all the lines of string.
  • 14. References • Regular expression tester: https://regex101.com/ • URLs to refer: https://www.regular-expressions.info/modifiers.html https://docs.python.org/3.6/library/re.html#re.I http://evc-cit.info/comsc020/python-regex-tutorial/ https://www.w3schools.com/jsref/jsref_obj_regexp.asp • Regex questions with solution (Pre-requisite: Anaconda must be installed in your machine to run jupyter notebook): • Other important documents to refer: Regex Notes Regex cheatsheet
  • 15. © Copyright 2021. All rights reserved. THANK YOU