SlideShare uma empresa Scribd logo
1 de 13
REGULAR
EXPRESSION
Application
Introduction
■ Regular Expression
– also known as RegEx
■ Is a sequence of characters that define a search pattern
– String matching
– Find and replace
■ The concept arose in the 1950s, when the American mathematician Stephen
Kleene formalized the description of a regular language.
Expressions –Word and Ranges
■ ABC
– Word equals to ABC
■ [a-z]
– Matching lowercase alphabets eg. a, b, c, d, ..., x, y, z
■ [A-Z]
– Matching uppercase alphabets eg. A, B, C, D, …,X,Y, Z
■ [0-9]
– Matching digits eg. 0, 1, 2, …, 8, 9
Expressions –Words with size
■ [a-z]+
– Any word containing all alphabets excluding null
– eg. aaaa, abc, owais, house …
■ [A-Z]*
– Any word containing all alphabets including null
■ [A-Za-z]*
– Any word containing upper and lower case alphabets
– Eg. Owais, House, house…
■ [A-Za-z0-9]{5}
– Word containing any alphabet and number with word of size 6
– Eg. abcde, Owais, abc12, 6011…
■ [A-Za-zd]{3, 8}
– Word of size ranging from 3 to 8
Expression – String matching
■ (admin|manager)
– String equal to admin or manager
■ (mon|tues|wednes|thurs|fri|satur|sun)day
– Matching week days
■ ^(math|calculus)$
– Starting and ending or exactly math or calculus
■ ^(math|calculus)
– Starting with word math or calculus
– Eg math is a subject.
Username RegEx
■ Size ranging from 3 to 12
■ Can contain small alphabets and digits
■ Expression
– [a-z0-9]{3, 12}
■ Starts with alphabet
– [a-z][a-z0-9]{2, 11}
Password RegEx
■ Size greater then 8
■ Contain alphabet and digits
■ Expression
– [a-zA-Z0-9]{8,}
■ Can contain special character
– [a-zA-Z0-9@#^%]{8,}
Email Address RegEx
■ Contains @ and .
■ Contains host eg gmail.com, pia.aero, github.io
■ Contains username eg. P146011
– Range 4 to 24
■ Expression
– [a-zA-Z0-9]{4,24}@[a-z0-9-].[a-z]{2, 4}
– Work for most email.
■ Dot mean “Any thing” in regex
– .a mean ending with a of size 2 eg, aa, ab, %a, 9a…
– A.*B mean starting with A and ending with B
Validate Date
■ 31-11-1999
– Expression: [0-9]{1,2}-[0-9][1,2]-[0-9]{4}
– Validates: 1-1-2000, 07-10-2016 …
– Problem…
– 0[0-9]|1[12]
■ for year
– 0[1-9]|[12][0-9]|3[01]
■ for month
– (19|20)[0-9]{2} from year ranging
■ 1900-2099
Where is it used?
■ Strong password validation
■ Login via email or phone in Facebook
■ Google Search Operators
– define: abracadabra
– #soachishti -> Find hashtags
– Made by * -> Unknown or wildcard terms.
■ Spam/Junk filter in email
– You won million dollars…
■ Data scraping
– Extracting name and email from websites
■ Text Processing
– Remove duplicate sentences
– Remove slang
C++ Code - Matching
#include <regex>
…
int main ()
{
string s = "subject";
regex e ("(sub)(.*)");
if (regex_match (s,e))
cout << "string object matchedn";
}
C++ Code - Replace
#include <regex>
#include <iterator>
...
int main ()
{
string s ("there is a subsequence in the stringn");
regex e ("b(sub)([^ ]*)"); // words beginning by "sub"
cout << regex_replace (s,e,"sub-$2");
// there is a sub-sequence in the string
}
THANKYOU!

Mais conteúdo relacionado

Mais de Syed Owais Ali Chishti (11)

Vehicle Classification
Vehicle ClassificationVehicle Classification
Vehicle Classification
 
Intro to Matlab + GUI
Intro to Matlab + GUIIntro to Matlab + GUI
Intro to Matlab + GUI
 
Cross-Platform Development
Cross-Platform DevelopmentCross-Platform Development
Cross-Platform Development
 
Shell Annual Report 2015
Shell Annual Report 2015Shell Annual Report 2015
Shell Annual Report 2015
 
Rabin Karp - String Matching Algorithm
Rabin Karp - String Matching AlgorithmRabin Karp - String Matching Algorithm
Rabin Karp - String Matching Algorithm
 
Handling character display in graphics mode using bios
Handling character display in graphics mode using biosHandling character display in graphics mode using bios
Handling character display in graphics mode using bios
 
Plagiarism
PlagiarismPlagiarism
Plagiarism
 
Chishti
ChishtiChishti
Chishti
 
Personality 2.0
Personality 2.0Personality 2.0
Personality 2.0
 
4th Law by Robert Greene
4th Law by Robert Greene4th Law by Robert Greene
4th Law by Robert Greene
 
Personality
PersonalityPersonality
Personality
 

Último

Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 

Último (20)

Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 

REGEXP

  • 2. Introduction ■ Regular Expression – also known as RegEx ■ Is a sequence of characters that define a search pattern – String matching – Find and replace ■ The concept arose in the 1950s, when the American mathematician Stephen Kleene formalized the description of a regular language.
  • 3. Expressions –Word and Ranges ■ ABC – Word equals to ABC ■ [a-z] – Matching lowercase alphabets eg. a, b, c, d, ..., x, y, z ■ [A-Z] – Matching uppercase alphabets eg. A, B, C, D, …,X,Y, Z ■ [0-9] – Matching digits eg. 0, 1, 2, …, 8, 9
  • 4. Expressions –Words with size ■ [a-z]+ – Any word containing all alphabets excluding null – eg. aaaa, abc, owais, house … ■ [A-Z]* – Any word containing all alphabets including null ■ [A-Za-z]* – Any word containing upper and lower case alphabets – Eg. Owais, House, house… ■ [A-Za-z0-9]{5} – Word containing any alphabet and number with word of size 6 – Eg. abcde, Owais, abc12, 6011… ■ [A-Za-zd]{3, 8} – Word of size ranging from 3 to 8
  • 5. Expression – String matching ■ (admin|manager) – String equal to admin or manager ■ (mon|tues|wednes|thurs|fri|satur|sun)day – Matching week days ■ ^(math|calculus)$ – Starting and ending or exactly math or calculus ■ ^(math|calculus) – Starting with word math or calculus – Eg math is a subject.
  • 6. Username RegEx ■ Size ranging from 3 to 12 ■ Can contain small alphabets and digits ■ Expression – [a-z0-9]{3, 12} ■ Starts with alphabet – [a-z][a-z0-9]{2, 11}
  • 7. Password RegEx ■ Size greater then 8 ■ Contain alphabet and digits ■ Expression – [a-zA-Z0-9]{8,} ■ Can contain special character – [a-zA-Z0-9@#^%]{8,}
  • 8. Email Address RegEx ■ Contains @ and . ■ Contains host eg gmail.com, pia.aero, github.io ■ Contains username eg. P146011 – Range 4 to 24 ■ Expression – [a-zA-Z0-9]{4,24}@[a-z0-9-].[a-z]{2, 4} – Work for most email. ■ Dot mean “Any thing” in regex – .a mean ending with a of size 2 eg, aa, ab, %a, 9a… – A.*B mean starting with A and ending with B
  • 9. Validate Date ■ 31-11-1999 – Expression: [0-9]{1,2}-[0-9][1,2]-[0-9]{4} – Validates: 1-1-2000, 07-10-2016 … – Problem… – 0[0-9]|1[12] ■ for year – 0[1-9]|[12][0-9]|3[01] ■ for month – (19|20)[0-9]{2} from year ranging ■ 1900-2099
  • 10. Where is it used? ■ Strong password validation ■ Login via email or phone in Facebook ■ Google Search Operators – define: abracadabra – #soachishti -> Find hashtags – Made by * -> Unknown or wildcard terms. ■ Spam/Junk filter in email – You won million dollars… ■ Data scraping – Extracting name and email from websites ■ Text Processing – Remove duplicate sentences – Remove slang
  • 11. C++ Code - Matching #include <regex> … int main () { string s = "subject"; regex e ("(sub)(.*)"); if (regex_match (s,e)) cout << "string object matchedn"; }
  • 12. C++ Code - Replace #include <regex> #include <iterator> ... int main () { string s ("there is a subsequence in the stringn"); regex e ("b(sub)([^ ]*)"); // words beginning by "sub" cout << regex_replace (s,e,"sub-$2"); // there is a sub-sequence in the string }