RegEx : Expressions and Parsing Examples
-
Upload
zeteo12 -
Category
Technology
-
view
499 -
download
4
description
Transcript of RegEx : Expressions and Parsing Examples
![Page 1: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/1.jpg)
RegEx : Expressions and Parsing Examples
![Page 2: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/2.jpg)
Overview
2
What is RegEx
Purpose of RegEx
How it Works
Advantages
Demonstration
Q&A
![Page 3: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/3.jpg)
Introduction to RegEx
3
RegEx is a sequence of characters for a search to match a pattern.
Arose in the 1950 by Stephen Kleene, an American Mathematician.
Regular expressions are composed of characters, metacharacters and quantifiers.
![Page 4: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/4.jpg)
Purpose of RegEx
4
To match the pieces of text within a larger document.
To capture the string.
RegEx is used in PERL, Java and other programming languages.
![Page 5: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/5.jpg)
How it Works
5
Regular Expressions: Exact Matches
rocks.
match
regular expression c k s
is okay.no match
![Page 6: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/6.jpg)
How it Works
6
Regular Expressions: Multiple Matches
Scrapple from the apple.
match 1 match 2
regular expression a p p l e
![Page 7: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/7.jpg)
Metacharacters of RegEx
7
. - Matches any single character.
\d - Matches a digit character.
\s - Matches any whitespace character including space, tab, form-feed, etc.
\w - Matches any word character including underscore.
\n - Matches a newline character.
^ - The beginning of a line
$ - The end of a line
![Page 8: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/8.jpg)
Metacharacters of RegEx
8
abc - Exactly this sequence of three letters
[abc] - Any one of the letters a, b, or c
[^abc] - Any character except one of the letters a, b, or c
[a-z] - Any one character from a through z
[a-zA-Z0-9]-Any one letter or digit.
![Page 9: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/9.jpg)
Quantifier
9
Quantifier specify the number of string pattern should occur in matching string.
* - Zero or more times.
+ - One or more times.
? - Zero or one time
{m,n} - Matches for atleast m times and atmost n times.
![Page 10: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/10.jpg)
Advantages
10
The regular expression syntax is declarative: The pattern "looks like" what you want to match.
Easily compatible with different programing languages.
Easier for non-programmers than code.
Less error prone than code.
Use in Compiler Construction.
![Page 12: RegEx : Expressions and Parsing Examples](https://reader030.fdocuments.net/reader030/viewer/2022020116/559929c91a28ab3b298b4750/html5/thumbnails/12.jpg)
Worldwide Offices:USA (Dallas)India (Pune)
Partner Offices:Monterrey (Mexico)Frankfurt (Germany)Stockholm (Sweden)
Email: [email protected] Corporate URL: www.zeteoconsulting.com