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

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
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
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
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
 
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
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
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
 
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
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
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
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 

Recently uploaded (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
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
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
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
 
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)
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
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
 
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
 
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
 
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
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 

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 }