SlideShare a Scribd company logo
10
Most read
11
Most read
15
Most read
Regular
Expressions
Presentedby:
Khuda Bux Magsi
(CSC-23F-259)
Context
• Introduction to Regular Expression
• Basic Syntax and Metacharacters
• Practical Applications
• Regex Tools
• Conclusion
Introduction
About Regular Expressions
What’s a Regular Expression?
• Regular expressions originated in 1951, when
mathematician Stephen Cole Kleene described regular
languages using his mathematical notation called regular
events.
• A regular expression, or regex, is a sequence of characters
used to define a search pattern.
• It's a powerful tool for finding, matching, and manipulating
text within a larger body of data.
• Regular Expressions are supported by many programming
languages and tools, making them a widely used tool in
software development.
What’s a Regular Expressions?
Example
Basic Syntax
Basic Syntax and Metacharacters
Basic Syntax of Regular
Expression
Regular expressions (regex) consist of a combination of literals and metacharacters that create
search patterns for matching text. Understanding the basic syntax is crucial for crafting
effective regex patterns.
Regular expressions (regex) have a specific syntax that defines how patterns are constructed.
Here's a breakdown of some fundamental elements:
 Literal Characters
 Special Characters
 Quantifiers
 Grouping
 Alternation
Basic Syntax of Regular
Expression
 Literal Characters
A literal character is any character that represents itself and is not interpreted as a
special symbol or metacharacter in regex. For instance, the letter a in a regex
pattern will match the character 'a' in the input text.
Examples of Literal Characters
Here are a few simple regex patterns using literal characters:
• ‘cat’: Matches the substring 'cat' in the text.
• Example: The cat is sleeping. (Matches 'cat')
Basic Syntax of Regular
Expression
 Special Characters
These are the workhorses of regex, adding power and flexibility to your patterns. Some common ones
include:
 . (Dot): Matches any single character except for newline characters.
 [] (Brackets): Define a set of characters that can match at a specific position. For example, "[abc]"
will match any of the letters a, b, or c.
 *(Asterisk): Matches the preceding character zero or more times. So, "a*b" will match "b", "ab",
"aab", "aaab", and so on.
 + (Plus): Matches the preceding character one or more times. "a+b" will match "ab", "aab", "aaab",
and so on, but not just "b".
 ? (Question Mark): Matches the preceding character zero or one time. "ca?t" will match "cat" or
"ct".
Basic Syntax of Regular
Expression
 Quantifiers:
These are special characters like "*", "+", and "?" that specify how many times the preceding character or group can be repeated.
Basic Syntax of Regular
Expression
 Grouping:
Parentheses are used to group parts of the pattern. This allows you to apply quantifiers or other operations to the entire group. For
instance, "(ab)*c" will match "c", "abc", "abbc", "abbbc", and so on.
Basic Syntax of Regular
Expression
 Alternation:
The pipe symbol ("|") is used for alternation. For example, "apple|banana" will match either "apple" or "banana".
Practical
Application
In Regular Expression
Validating Input
• Validating user input is crucial for ensuring data integrity and security in applications.
Here are common validation techniques for specific types of user input.
Searching and Replacing
• Searching and replacing text based on patterns is a common task in text processing. Here
are examples of how to search for patterns and replace them with desired text.
Regex Tools &
Libraries
Regular Expression
Regex Tools
Online Regex Testers
 Regex101: An interactive web-based tool that supports
multiple regex flavors, including PCRE, JavaScript, and
Python. It provides real-time regex matching, a detailed
explanation of the regex, and a breakdown of each
component.
 RegExr: Another online tool that offers a user-friendly
interface for creating and testing regular expressions. It
includes a library of regex snippets and a cheat sheet for
common patterns.
 RegexPlanet: Supports various programming languages,
providing a versatile platform for testing regex patterns
against sample text.
Regex Tools
Integrated Development Environment (IDE) Plugins
 Regex Plugin for Visual Studio Code: Enhances the regex capabilities within the VSCode
environment, allowing for testing and debugging regex patterns directly in the editor.
 IntelliJ IDEA Regex Plugin: Provides similar functionality for IntelliJ-based IDEs, offering syntax
highlighting, pattern matching, and error detection.
Conclusion
 Indispensable Tool:
• Regular expressions are essential for modern programming and text processing.
• They provide a flexible and powerful method for searching, matching, and manipulating
strings.
 Versatile Applications:
• Useful for a wide range of tasks, from simple text searches to complex parsing and data
extraction.
• Applicable in various domains, including data validation, web scraping, and log file analysis.
Thank you
Any
Question..
Feel free to ask

More Related Content

Similar to Regular Expressions(Theory of programming languages)) (20)

PPTX
Regular Expression
Mahzad Zahedi
 
PPT
RegEx Parsing
Anjali Rao
 
PPTX
Regular Expression Crash Course
Imran Qasim
 
ODP
Regex Presentation
arnolambert
 
ODP
Regex Presentation
arnolambert
 
PDF
Regular Expressions 101
Kai Koenig
 
PDF
Python (regular expression)
Chirag Shetty
 
ODP
Regular Expressions and You
James Armes
 
PPT
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
PPTX
Regular expressions
Eran Zimbler
 
PPTX
Mikhail Khristophorov "Introduction to Regular Expressions"
LogeekNightUkraine
 
PPTX
Regular Expressions Introduction Anthony Rudd CS
gapati2964
 
PPTX
Finaal application on regular expression
Gagan019
 
PDF
Regular expression in python for students
Manoj PAtil
 
DOCX
Python - Regular Expressions
Mukesh Tekwani
 
PDF
Python Programming - XI. String Manipulation and Regular Expressions
Ranel Padon
 
PDF
Regular expressions
varun kumar karuna
 
PPT
Regular Expression in Action
Folio3 Software
 
PDF
2013 - Andrei Zmievski: Clínica Regex
PHP Conference Argentina
 
PPTX
Regular expressions
Ignaz Wanders
 
Regular Expression
Mahzad Zahedi
 
RegEx Parsing
Anjali Rao
 
Regular Expression Crash Course
Imran Qasim
 
Regex Presentation
arnolambert
 
Regex Presentation
arnolambert
 
Regular Expressions 101
Kai Koenig
 
Python (regular expression)
Chirag Shetty
 
Regular Expressions and You
James Armes
 
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
Regular expressions
Eran Zimbler
 
Mikhail Khristophorov "Introduction to Regular Expressions"
LogeekNightUkraine
 
Regular Expressions Introduction Anthony Rudd CS
gapati2964
 
Finaal application on regular expression
Gagan019
 
Regular expression in python for students
Manoj PAtil
 
Python - Regular Expressions
Mukesh Tekwani
 
Python Programming - XI. String Manipulation and Regular Expressions
Ranel Padon
 
Regular expressions
varun kumar karuna
 
Regular Expression in Action
Folio3 Software
 
2013 - Andrei Zmievski: Clínica Regex
PHP Conference Argentina
 
Regular expressions
Ignaz Wanders
 

Recently uploaded (20)

PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
community health nursing question paper 2.pdf
Prince kumar
 
Ad

Regular Expressions(Theory of programming languages))

  • 2. Context • Introduction to Regular Expression • Basic Syntax and Metacharacters • Practical Applications • Regex Tools • Conclusion
  • 4. What’s a Regular Expression? • Regular expressions originated in 1951, when mathematician Stephen Cole Kleene described regular languages using his mathematical notation called regular events. • A regular expression, or regex, is a sequence of characters used to define a search pattern. • It's a powerful tool for finding, matching, and manipulating text within a larger body of data. • Regular Expressions are supported by many programming languages and tools, making them a widely used tool in software development.
  • 5. What’s a Regular Expressions? Example
  • 6. Basic Syntax Basic Syntax and Metacharacters
  • 7. Basic Syntax of Regular Expression Regular expressions (regex) consist of a combination of literals and metacharacters that create search patterns for matching text. Understanding the basic syntax is crucial for crafting effective regex patterns. Regular expressions (regex) have a specific syntax that defines how patterns are constructed. Here's a breakdown of some fundamental elements:  Literal Characters  Special Characters  Quantifiers  Grouping  Alternation
  • 8. Basic Syntax of Regular Expression  Literal Characters A literal character is any character that represents itself and is not interpreted as a special symbol or metacharacter in regex. For instance, the letter a in a regex pattern will match the character 'a' in the input text. Examples of Literal Characters Here are a few simple regex patterns using literal characters: • ‘cat’: Matches the substring 'cat' in the text. • Example: The cat is sleeping. (Matches 'cat')
  • 9. Basic Syntax of Regular Expression  Special Characters These are the workhorses of regex, adding power and flexibility to your patterns. Some common ones include:  . (Dot): Matches any single character except for newline characters.  [] (Brackets): Define a set of characters that can match at a specific position. For example, "[abc]" will match any of the letters a, b, or c.  *(Asterisk): Matches the preceding character zero or more times. So, "a*b" will match "b", "ab", "aab", "aaab", and so on.  + (Plus): Matches the preceding character one or more times. "a+b" will match "ab", "aab", "aaab", and so on, but not just "b".  ? (Question Mark): Matches the preceding character zero or one time. "ca?t" will match "cat" or "ct".
  • 10. Basic Syntax of Regular Expression  Quantifiers: These are special characters like "*", "+", and "?" that specify how many times the preceding character or group can be repeated.
  • 11. Basic Syntax of Regular Expression  Grouping: Parentheses are used to group parts of the pattern. This allows you to apply quantifiers or other operations to the entire group. For instance, "(ab)*c" will match "c", "abc", "abbc", "abbbc", and so on.
  • 12. Basic Syntax of Regular Expression  Alternation: The pipe symbol ("|") is used for alternation. For example, "apple|banana" will match either "apple" or "banana".
  • 14. Validating Input • Validating user input is crucial for ensuring data integrity and security in applications. Here are common validation techniques for specific types of user input.
  • 15. Searching and Replacing • Searching and replacing text based on patterns is a common task in text processing. Here are examples of how to search for patterns and replace them with desired text.
  • 17. Regex Tools Online Regex Testers  Regex101: An interactive web-based tool that supports multiple regex flavors, including PCRE, JavaScript, and Python. It provides real-time regex matching, a detailed explanation of the regex, and a breakdown of each component.  RegExr: Another online tool that offers a user-friendly interface for creating and testing regular expressions. It includes a library of regex snippets and a cheat sheet for common patterns.  RegexPlanet: Supports various programming languages, providing a versatile platform for testing regex patterns against sample text.
  • 18. Regex Tools Integrated Development Environment (IDE) Plugins  Regex Plugin for Visual Studio Code: Enhances the regex capabilities within the VSCode environment, allowing for testing and debugging regex patterns directly in the editor.  IntelliJ IDEA Regex Plugin: Provides similar functionality for IntelliJ-based IDEs, offering syntax highlighting, pattern matching, and error detection.
  • 19. Conclusion  Indispensable Tool: • Regular expressions are essential for modern programming and text processing. • They provide a flexible and powerful method for searching, matching, and manipulating strings.  Versatile Applications: • Useful for a wide range of tasks, from simple text searches to complex parsing and data extraction. • Applicable in various domains, including data validation, web scraping, and log file analysis.