SlideShare a Scribd company logo
1 of 17
Download to read offline
Regular Expressions
Part 1: Basic Building Blocks
What is a regular
expression?
Simple, an expression used regularly!
Introducing Regular Expressions
/ah/
Yes that is a regular expression!
You don’t believe me, try http://rubular.com/r/31xqIzPmPe
/aah/
Wonder how you’ll match
/aaaaaaaa...h/
Repetition Token
Token Property Regex Example Test String
{m, n} Match exact
occurrences of a
character/token
a{1,3}h ah, aah, aaah, aaaah,
h, ha, aha
? Matches 0 or 1
occurrence of a
token
a?h ah, aah, aaah, aaaah,
h, ha, aha
+ Matches 1 or more
occurrence of a
token
a+h ah, aah, aaah, aaaah,
h, ha, aha
* Matches 0 or more
occurrence of a
token
a*h ah, aah, aaah, aaaah,
h, ha, aha
Repetition Token
Token Property Regex Example Test String
{m, n} Match exact
occurrences of a
character/token
a{1,3}h ah, aah, aaah, aaaah,
h, ha, haaha
? Matches 0 or 1
occurrence of a
token
a?h ah, aah, aaah, aaaah,
h, ha, haaha
+ Matches 1 or more
occurrence of a
token
a+h ah, aah, aaah, aaaah,
h, ha, haaha
* Matches 0 or more
occurrence of a
token
a*h ah, aah, aaah, aaaah,
h, ha, haaha
Challenge 1:
Highlight the
first match for
string in
orange
Anchor Token
Token Property Regex Example Test String
^ Matches the
position at the start
of Line
^ah ah, aah, ha, aha,
ha<newline>ah
$ Matches the
position at the end
of Line
ah$ ah, aah, ha, aha,
ah<newline>ha
A Matches the
position at the start
of String
Aah ah, aah, ha, aha,
ha<newline>ah
Z Matches the
position at the end
of String
ahZ ah, aah, ha, aha,
ah<newline>ha
Character Token
Token Property Regex Example Test String
[a-zA-Z0-9] Matches one out of
several characters
gr[ea]y grey, gray, greay
[^a-zA-Z0-9] Matches any
character which is
not one of those in
the character set.
q[^u] qatar, Iraq,
[a-zA-Z0-9]+ Matches repeating
characters
[0-9]+ 333, 222, 123
[1st - [2nd]] Matches any one
character in first list
but not in the
second list.
[0-9-[02468]]+ 1357, 124, 111
Shortcut Character Token
Token Property Regex Example Test String
d Matches any digit d{1,9} 1, 123456789,
1234235259
s Matches any
whitespace
character
s+$ t, blank line with
spaces.
w Matches any word
character i.e.
letters, numbers, _
w{1,5} foo_1, $foo_1
D, S, W Matches opposite of
the above character
classes.
D+ Foobar, hello
world123!
Challenge 2:
Match 10 digit
mobile number
entered by user on
your signup form.
Ultimate Character - The .
The dot matches one of any character except the line break.
Challenge 2
^d{10,10}$
^$: Are anchor tags to
anchor to start and end of
input, prevents matching
abc0000000000
{10, 10}: matches
specifically 10 numbers
Solutions
Challenge 1
/a{1,3}h/ haaha
/a?h/ haaha
/a+h/ haaha
/a*h/ haaha
Let’s not get greedy.
We’ll dive deeper later!
Questions?

More Related Content

What's hot

Waf bypassing Techniques
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing TechniquesAvinash Thapa
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programmingRodolfo Finochietti
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressionsBen Brumfield
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented ProgrammingScott Wlaschin
 
Regular expression
Regular expressionRegular expression
Regular expressionRajon
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsMesut Günes
 
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...Garage4hackers.com
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionLambert Lum
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming LanguageJaeju Kim
 
Regex - Regular Expression Basics
Regex - Regular Expression BasicsRegex - Regular Expression Basics
Regex - Regular Expression BasicsEterna Han Tsai
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & StreamsEyal Vardi
 
Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyRoger Barnes
 
Scaling LoL Chat to 70M Players
Scaling LoL Chat to 70M PlayersScaling LoL Chat to 70M Players
Scaling LoL Chat to 70M PlayersMichał Ptaszek
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Raj Rajandran
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기영우 박
 
Taking Laravel to the edge with HTTP caching and Varnish
Taking Laravel to the edge with HTTP caching and VarnishTaking Laravel to the edge with HTTP caching and Varnish
Taking Laravel to the edge with HTTP caching and VarnishThijs Feryn
 

What's hot (20)

Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Waf bypassing Techniques
Waf bypassing TechniquesWaf bypassing Techniques
Waf bypassing Techniques
 
Restful api
Restful apiRestful api
Restful api
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented Programming
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) Fundamentals
 
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
Garage4Hackers Ranchoddas Webcast Series - Bypassing Modern WAF's Exemplified...
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
Regex - Regular Expression Basics
Regex - Regular Expression BasicsRegex - Regular Expression Basics
Regex - Regular Expression Basics
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
Building data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemyBuilding data flows with Celery and SQLAlchemy
Building data flows with Celery and SQLAlchemy
 
Scaling LoL Chat to 70M Players
Scaling LoL Chat to 70M PlayersScaling LoL Chat to 70M Players
Scaling LoL Chat to 70M Players
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기Django admin site 커스텀하여 적극적으로 활용하기
Django admin site 커스텀하여 적극적으로 활용하기
 
Taking Laravel to the edge with HTTP caching and Varnish
Taking Laravel to the edge with HTTP caching and VarnishTaking Laravel to the edge with HTTP caching and Varnish
Taking Laravel to the edge with HTTP caching and Varnish
 

Similar to Introducing Regular Expressions

An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressionsYamagata Europe
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracleLogan Palanisamy
 
Looking for Patterns
Looking for PatternsLooking for Patterns
Looking for PatternsKeith Wright
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007Geoffrey Dunn
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netProgrammer Blog
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regexwayn
 
Regex startup
Regex startupRegex startup
Regex startupPayPal
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)Chirag Shetty
 
Basta mastering regex power
Basta mastering regex powerBasta mastering regex power
Basta mastering regex powerMax Kleiner
 
Regular Expression Cheat Sheet
Regular Expression Cheat SheetRegular Expression Cheat Sheet
Regular Expression Cheat SheetSydneyJohnson57
 

Similar to Introducing Regular Expressions (20)

Regex Basics
Regex BasicsRegex Basics
Regex Basics
 
2013 - Andrei Zmievski: Clínica Regex
2013 - Andrei Zmievski: Clínica Regex2013 - Andrei Zmievski: Clínica Regex
2013 - Andrei Zmievski: Clínica Regex
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressions
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
 
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 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Regular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.netRegular Expressions in PHP, MySQL by programmerblog.net
Regular Expressions in PHP, MySQL by programmerblog.net
 
Patterns
PatternsPatterns
Patterns
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
 
Regex startup
Regex startupRegex startup
Regex startup
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)
 
Basta mastering regex power
Basta mastering regex powerBasta mastering regex power
Basta mastering regex power
 
Regex Intro
Regex IntroRegex Intro
Regex Intro
 
Regular Expression Cheat Sheet
Regular Expression Cheat SheetRegular Expression Cheat Sheet
Regular Expression Cheat Sheet
 
Ruby RegEx
Ruby RegExRuby RegEx
Ruby RegEx
 
RegEx Book.pdf
RegEx Book.pdfRegEx Book.pdf
RegEx Book.pdf
 
Lecture 10.pdf
Lecture 10.pdfLecture 10.pdf
Lecture 10.pdf
 

More from Neha Jain

Bringing HTML5 uploads to SlideShare
Bringing HTML5 uploads to SlideShareBringing HTML5 uploads to SlideShare
Bringing HTML5 uploads to SlideShareNeha Jain
 
The power of happiness
The power of happinessThe power of happiness
The power of happinessNeha Jain
 
Houserentreceipt
HouserentreceiptHouserentreceipt
HouserentreceiptNeha Jain
 
Slideshareistestinginfographics regularupload
Slideshareistestinginfographics regularuploadSlideshareistestinginfographics regularupload
Slideshareistestinginfographics regularuploadNeha Jain
 
House rent receipt
House rent receiptHouse rent receipt
House rent receiptNeha Jain
 
Byte of vim_v051
Byte of vim_v051Byte of vim_v051
Byte of vim_v051Neha Jain
 

More from Neha Jain (7)

FindIn
FindInFindIn
FindIn
 
Bringing HTML5 uploads to SlideShare
Bringing HTML5 uploads to SlideShareBringing HTML5 uploads to SlideShare
Bringing HTML5 uploads to SlideShare
 
The power of happiness
The power of happinessThe power of happiness
The power of happiness
 
Houserentreceipt
HouserentreceiptHouserentreceipt
Houserentreceipt
 
Slideshareistestinginfographics regularupload
Slideshareistestinginfographics regularuploadSlideshareistestinginfographics regularupload
Slideshareistestinginfographics regularupload
 
House rent receipt
House rent receiptHouse rent receipt
House rent receipt
 
Byte of vim_v051
Byte of vim_v051Byte of vim_v051
Byte of vim_v051
 

Recently uploaded

ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderjuancarlos286641
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Amil baba
 
Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...sahb78428
 
solar wireless electric vechicle charging system
solar wireless electric vechicle charging systemsolar wireless electric vechicle charging system
solar wireless electric vechicle charging systemgokuldongala
 
Mohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxMohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxKISHAN KUMAR
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...soginsider
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxwendy cai
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technologyabdulkadirmukarram03
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxjasonsedano2
 
Landsman converter for power factor improvement
Landsman converter for power factor improvementLandsman converter for power factor improvement
Landsman converter for power factor improvementVijayMuni2
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfNaveenVerma126
 
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchrohitcse52
 
Graphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesGraphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesDIPIKA83
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....santhyamuthu1
 
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...amrabdallah9
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfJulia Kaye
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsYusuf Yıldız
 

Recently uploaded (20)

Présentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdfPrésentation IIRB 2024 Chloe Dufrane.pdf
Présentation IIRB 2024 Chloe Dufrane.pdf
 
ASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entenderASME BPVC 2023 Section I para leer y entender
ASME BPVC 2023 Section I para leer y entender
 
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
Best-NO1 Best Rohani Amil In Lahore Kala Ilam In Lahore Kala Jadu Amil In Lah...
 
Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...Clutches and brkesSelect any 3 position random motion out of real world and d...
Clutches and brkesSelect any 3 position random motion out of real world and d...
 
solar wireless electric vechicle charging system
solar wireless electric vechicle charging systemsolar wireless electric vechicle charging system
solar wireless electric vechicle charging system
 
Mohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptxMohs Scale of Hardness, Hardness Scale.pptx
Mohs Scale of Hardness, Hardness Scale.pptx
 
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...Transforming Process Safety Management: Challenges, Benefits, and Transition ...
Transforming Process Safety Management: Challenges, Benefits, and Transition ...
 
Nodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptxNodal seismic construction requirements.pptx
Nodal seismic construction requirements.pptx
 
The relationship between iot and communication technology
The relationship between iot and communication technologyThe relationship between iot and communication technology
The relationship between iot and communication technology
 
nvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptxnvidia AI-gtc 2024 partial slide deck.pptx
nvidia AI-gtc 2024 partial slide deck.pptx
 
Landsman converter for power factor improvement
Landsman converter for power factor improvementLandsman converter for power factor improvement
Landsman converter for power factor improvement
 
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdfSummer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
Summer training report on BUILDING CONSTRUCTION for DIPLOMA Students.pdf
 
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai searchChatGPT-and-Generative-AI-Landscape Working of generative ai search
ChatGPT-and-Generative-AI-Landscape Working of generative ai search
 
Graphics Primitives and CG Display Devices
Graphics Primitives and CG Display DevicesGraphics Primitives and CG Display Devices
Graphics Primitives and CG Display Devices
 
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
SATELITE COMMUNICATION UNIT 1 CEC352 REGULATION 2021 PPT BASICS OF SATELITE ....
 
Lecture 2 .pptx
Lecture 2                            .pptxLecture 2                            .pptx
Lecture 2 .pptx
 
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
Strategies of Urban Morphologyfor Improving Outdoor Thermal Comfort and Susta...
 
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdfsdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
sdfsadopkjpiosufoiasdoifjasldkjfl a asldkjflaskdjflkjsdsdf
 
Modelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovationsModelling Guide for Timber Structures - FPInnovations
Modelling Guide for Timber Structures - FPInnovations
 
Présentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdfPrésentation IIRB 2024 Marine Cordonnier.pdf
Présentation IIRB 2024 Marine Cordonnier.pdf
 

Introducing Regular Expressions

  • 1. Regular Expressions Part 1: Basic Building Blocks
  • 2. What is a regular expression?
  • 3. Simple, an expression used regularly!
  • 5. /ah/ Yes that is a regular expression!
  • 6. You don’t believe me, try http://rubular.com/r/31xqIzPmPe /aah/
  • 7. Wonder how you’ll match /aaaaaaaa...h/
  • 8. Repetition Token Token Property Regex Example Test String {m, n} Match exact occurrences of a character/token a{1,3}h ah, aah, aaah, aaaah, h, ha, aha ? Matches 0 or 1 occurrence of a token a?h ah, aah, aaah, aaaah, h, ha, aha + Matches 1 or more occurrence of a token a+h ah, aah, aaah, aaaah, h, ha, aha * Matches 0 or more occurrence of a token a*h ah, aah, aaah, aaaah, h, ha, aha
  • 9. Repetition Token Token Property Regex Example Test String {m, n} Match exact occurrences of a character/token a{1,3}h ah, aah, aaah, aaaah, h, ha, haaha ? Matches 0 or 1 occurrence of a token a?h ah, aah, aaah, aaaah, h, ha, haaha + Matches 1 or more occurrence of a token a+h ah, aah, aaah, aaaah, h, ha, haaha * Matches 0 or more occurrence of a token a*h ah, aah, aaah, aaaah, h, ha, haaha Challenge 1: Highlight the first match for string in orange
  • 10. Anchor Token Token Property Regex Example Test String ^ Matches the position at the start of Line ^ah ah, aah, ha, aha, ha<newline>ah $ Matches the position at the end of Line ah$ ah, aah, ha, aha, ah<newline>ha A Matches the position at the start of String Aah ah, aah, ha, aha, ha<newline>ah Z Matches the position at the end of String ahZ ah, aah, ha, aha, ah<newline>ha
  • 11. Character Token Token Property Regex Example Test String [a-zA-Z0-9] Matches one out of several characters gr[ea]y grey, gray, greay [^a-zA-Z0-9] Matches any character which is not one of those in the character set. q[^u] qatar, Iraq, [a-zA-Z0-9]+ Matches repeating characters [0-9]+ 333, 222, 123 [1st - [2nd]] Matches any one character in first list but not in the second list. [0-9-[02468]]+ 1357, 124, 111
  • 12. Shortcut Character Token Token Property Regex Example Test String d Matches any digit d{1,9} 1, 123456789, 1234235259 s Matches any whitespace character s+$ t, blank line with spaces. w Matches any word character i.e. letters, numbers, _ w{1,5} foo_1, $foo_1 D, S, W Matches opposite of the above character classes. D+ Foobar, hello world123!
  • 13. Challenge 2: Match 10 digit mobile number entered by user on your signup form.
  • 14. Ultimate Character - The . The dot matches one of any character except the line break.
  • 15. Challenge 2 ^d{10,10}$ ^$: Are anchor tags to anchor to start and end of input, prevents matching abc0000000000 {10, 10}: matches specifically 10 numbers Solutions Challenge 1 /a{1,3}h/ haaha /a?h/ haaha /a+h/ haaha /a*h/ haaha
  • 16. Let’s not get greedy. We’ll dive deeper later!