SlideShare uma empresa Scribd logo
1 de 10
Regular Expressions
What are Regular Expressions?
• They are a way of specifying patterns
• Specifically patterns of symbols
  – A set of rules
  – A mini language
  – A tiny, highly specialised programming
    language
• Number one use is for pattern
  matching – ie: finding things
Where could you use this
         awesome skill?
•   Python
•   Perl, C, Java, VB.NET, Javascript
•   Yahoo Widgets
•   Excel, Word ….
Basic RegEx Syntax
[abc] = either a, b or c (class)
a|b = a or b
[a-z] = anything between a and z
[^5] = anything except 5
. = anything (except a new line)
* = multiple instances of the same char (0->)
 The backslash is a metacharacter
(ab)* Round brackets group chars together
                .^$*+?{[]|()
Exercise 1
Which of the following matches regexp a(ab)*a
• abababa
• aaba
• aabbaa
• aba
• aabababa
Exercise 2
•   Which of the following matches regexp abc|xyz
•   abc
•   xyz
•   abc|xyz
Repetitions
• a* = zero or more repetitions of a
• a+ = one or more repetitions of a
• a? = zero or one repetitions of a
  – (in other words, might not be there)
Exercise 3
•   Which of the following matches regexp ab+c?
•   abc
•   ac
•   abbb
•   bbc
Exercise 4
•   Which of the following matches regexp a.[bc]+
•   abc
•   abbbbbbbb
•   azc
•   abcbcbcbc
•   ac
•   asccbbbbcbcccc
Regular expressions

Mais conteúdo relacionado

Mais procurados

16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
wayn
 

Mais procurados (16)

Lisp
LispLisp
Lisp
 
Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Declarativemagic
DeclarativemagicDeclarativemagic
Declarativemagic
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) Fundamentals
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Aaa ped-3. Pythond: advanced concepts
Aaa ped-3. Pythond: advanced conceptsAaa ped-3. Pythond: advanced concepts
Aaa ped-3. Pythond: advanced concepts
 
Programming in python - Week 3
Programming in python - Week 3Programming in python - Week 3
Programming in python - Week 3
 
Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer) Quick Select (Decrease and Conquer)
Quick Select (Decrease and Conquer)
 
Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...Processing data with Python, using standard library modules you (probably) ne...
Processing data with Python, using standard library modules you (probably) ne...
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressions
 
Algorithms Intro Lecture
Algorithms Intro LectureAlgorithms Intro Lecture
Algorithms Intro Lecture
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 

Destaque (7)

Comunicacion y Transmicion de Datos
Comunicacion y Transmicion  de DatosComunicacion y Transmicion  de Datos
Comunicacion y Transmicion de Datos
 
Feminism Scholarly presentation
Feminism Scholarly presentationFeminism Scholarly presentation
Feminism Scholarly presentation
 
PD:Orienting Teachers to NROC
PD:Orienting Teachers to NROCPD:Orienting Teachers to NROC
PD:Orienting Teachers to NROC
 
The Culture Industry
The  Culture  IndustryThe  Culture  Industry
The Culture Industry
 
McKonly & Asbury Webinar - Mitigating Taxes for Contractors: Section 460 Appl...
McKonly & Asbury Webinar - Mitigating Taxes for Contractors: Section 460 Appl...McKonly & Asbury Webinar - Mitigating Taxes for Contractors: Section 460 Appl...
McKonly & Asbury Webinar - Mitigating Taxes for Contractors: Section 460 Appl...
 
Eternale Beauty Device
Eternale Beauty DeviceEternale Beauty Device
Eternale Beauty Device
 
La Sociedad De La InformaciëN
La Sociedad De La InformaciëNLa Sociedad De La InformaciëN
La Sociedad De La InformaciëN
 

Semelhante a Regular expressions

Algebraic Expressions PPT.pptx
Algebraic Expressions PPT.pptxAlgebraic Expressions PPT.pptx
Algebraic Expressions PPT.pptx
NardoGunayonFinez
 
Ruby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と HashRuby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と Hash
higaki
 
Precalc 8.19.13
Precalc 8.19.13Precalc 8.19.13
Precalc 8.19.13
Ron Eick
 
Python advanced 2. regular expression in python
Python advanced 2. regular expression in pythonPython advanced 2. regular expression in python
Python advanced 2. regular expression in python
John(Qiang) Zhang
 

Semelhante a Regular expressions (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
 
Evaluating Algebraic Expressions presentation PPT.
Evaluating Algebraic Expressions presentation PPT.Evaluating Algebraic Expressions presentation PPT.
Evaluating Algebraic Expressions presentation PPT.
 
Algebraic Expressions PPT.pptx
Algebraic Expressions PPT.pptxAlgebraic Expressions PPT.pptx
Algebraic Expressions PPT.pptx
 
Algebraic Expressions PPT.pptx
Algebraic Expressions PPT.pptxAlgebraic Expressions PPT.pptx
Algebraic Expressions PPT.pptx
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Lec3
Lec3Lec3
Lec3
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
04 Syntax Analysis.pdf
04 Syntax Analysis.pdf04 Syntax Analysis.pdf
04 Syntax Analysis.pdf
 
Python - Lecture 7
Python - Lecture 7Python - Lecture 7
Python - Lecture 7
 
Ruby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と HashRuby初級者向けレッスン 48回 ─── Array と Hash
Ruby初級者向けレッスン 48回 ─── Array と Hash
 
Precalc 8.19.13
Precalc 8.19.13Precalc 8.19.13
Precalc 8.19.13
 
Erlang
ErlangErlang
Erlang
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Mit6 094 iap10_lec03
Mit6 094 iap10_lec03Mit6 094 iap10_lec03
Mit6 094 iap10_lec03
 
Python advanced 2. regular expression in python
Python advanced 2. regular expression in pythonPython advanced 2. regular expression in python
Python advanced 2. regular expression in python
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
 
Regexes in .NET
Regexes in .NETRegexes in .NET
Regexes in .NET
 

Mais de grahamwell (20)

Pseudocode
PseudocodePseudocode
Pseudocode
 
Excel =if function
Excel =if functionExcel =if function
Excel =if function
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
The software story
The software storyThe software story
The software story
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
 
Database field types
Database field typesDatabase field types
Database field types
 
Databases 101
Databases 101Databases 101
Databases 101
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and types
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your project
 
The rail fence
The rail fenceThe rail fence
The rail fence
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryption
 
Server side scripts
Server side scriptsServer side scripts
Server side scripts
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and control
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Regular expressions

  • 2. What are Regular Expressions? • They are a way of specifying patterns • Specifically patterns of symbols – A set of rules – A mini language – A tiny, highly specialised programming language • Number one use is for pattern matching – ie: finding things
  • 3. Where could you use this awesome skill? • Python • Perl, C, Java, VB.NET, Javascript • Yahoo Widgets • Excel, Word ….
  • 4. Basic RegEx Syntax [abc] = either a, b or c (class) a|b = a or b [a-z] = anything between a and z [^5] = anything except 5 . = anything (except a new line) * = multiple instances of the same char (0->) The backslash is a metacharacter (ab)* Round brackets group chars together .^$*+?{[]|()
  • 5. Exercise 1 Which of the following matches regexp a(ab)*a • abababa • aaba • aabbaa • aba • aabababa
  • 6. Exercise 2 • Which of the following matches regexp abc|xyz • abc • xyz • abc|xyz
  • 7. Repetitions • a* = zero or more repetitions of a • a+ = one or more repetitions of a • a? = zero or one repetitions of a – (in other words, might not be there)
  • 8. Exercise 3 • Which of the following matches regexp ab+c? • abc • ac • abbb • bbc
  • 9. Exercise 4 • Which of the following matches regexp a.[bc]+ • abc • abbbbbbbb • azc • abcbcbcbc • ac • asccbbbbcbcccc