SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Regular Expressions
Part 1: Basic Building Blocks
What is a regular
expression?
Simple, an expression used regularly!
/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?

Mais conteúdo relacionado

Mais procurados

Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsDanny Bryant
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsMatt Casto
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Raj Rajandran
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and responseSahil Agarwal
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisIan Macali
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptxSunilWork1
 
Saturn 2018 rest.li
Saturn 2018 rest.liSaturn 2018 rest.li
Saturn 2018 rest.liMin Chen
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)Aditya pratap Singh
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajaxPihu Goel
 
OWASP Top 10 (2013) 正體中文版
OWASP Top 10 (2013) 正體中文版OWASP Top 10 (2013) 正體中文版
OWASP Top 10 (2013) 正體中文版Bruce Chen
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controlsGuddu gupta
 

Mais procurados (20)

Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Offzone | Another waf bypass
Offzone | Another waf bypassOffzone | Another waf bypass
Offzone | Another waf bypass
 
HTTP request and response
HTTP request and responseHTTP request and response
HTTP request and response
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective IndexingMongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
MongoDB .local Toronto 2019: Tips and Tricks for Effective Indexing
 
PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Asymptotic Notations.pptx
Asymptotic Notations.pptxAsymptotic Notations.pptx
Asymptotic Notations.pptx
 
Saturn 2018 rest.li
Saturn 2018 rest.liSaturn 2018 rest.li
Saturn 2018 rest.li
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
 
Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
 
N queen problem
N queen problemN queen problem
N queen problem
 
N Queens problem
N Queens problemN Queens problem
N Queens problem
 
OWASP Top 10 (2013) 正體中文版
OWASP Top 10 (2013) 正體中文版OWASP Top 10 (2013) 正體中文版
OWASP Top 10 (2013) 正體中文版
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Último (20)

DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

Introducing Regular Expressions

  • 1. Regular Expressions Part 1: Basic Building Blocks
  • 2. What is a regular expression?
  • 3. Simple, an expression used regularly!
  • 4.
  • 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!