SlideShare a Scribd company logo
1 of 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!

More Related Content

More from 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
 

Recently uploaded

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
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Recently uploaded (20)

LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.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)
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

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 }