SlideShare une entreprise Scribd logo
1  sur  12
REGULAR EXPRESSION IN
ACTION
Brief overview of Regular Expression building blocks and
tools with a practical example
REGULAR EXPRESSIONS PROVIDE A CONCISE AND FLEXIBLE MEANS FOR MATCHING STRINGS OF
TEXT, SUCH AS PARTICULAR CHARACTERS, WORDS, OR PATTERNS OF CHARACTERS.
WHAT ARE REGULAR EXPRESSIONS
THE REGEX COACH IS A GRAPHICAL APPLICATION
FOR WINDOWS WHICH CAN BE USED TO
EXPERIMENT WITH REGULAR EXPRESSIONS
INTERACTIVELY.
◦ http://weitz.de/regex-coach/
Sublime Text is a text editor that has support of find and
replace using Regular Expressions.
Web based Regular Expressions tester.
◦ http://www.regular-expressions.info/
THE MOST BASIC REGULAR EXPRESSION CONSISTS OF A LITERAL
which behaves just like string matching. For e.g.
◦ cat will match cat in About cats and dogs.
Special characters known as meta characters needs to be escaped with a  in
regular expressions if they are used as part of a literal:
◦ dogs.will match dogs. in About cats and dogs.
Meta characters are:
◦ [  ^ $ . | ? * + ( ) {
WITH A "CHARACTER CLASS", ALSO CALLED "CHARACTER SET", YOU CAN TELL
THE REGEX ENGINE TO MATCH ONLY ONE OUT OF SEVERAL CHARACTERS.
FOR E.G.
◦ gr[ae]ywill match grey and gray both.
Ranges can be specified using dash. For e.g.
◦ [0-9]will match any digit from 0 to 9.
◦ [0-9a-fA-F]will match any single hexadecimal digit.
Caret after the opening square bracket will negate the character class.
• The result is that the character class will match any character that is not
• in the character class. For e.g.
◦ [^0-9] will match any thing except number.
◦ q[^u] will not match Iraq but it will match Iraq is a country
Meta characters works fine without escaping in Character classes. For e.g.
◦ [+*]is a valid expression and match either * or +.
There are some pre-defined character classes known as short hand
character classes:
◦ w stands for[A-Za-z0-9_]
◦ s stands for[ trn]
◦ d stands for[0-9]
If a character class is repeated by using the ?, * or + operators, the
entire character class will be repeated, and not just the character that it
matched. For e.g.
◦ [0-9]+ can match 837 as well as 222
◦ ([0-9])1+ will match 222 but not 837.
The famous dot “.” operator matches anything. For e.g.
◦ a.b will match abb, aab, a+b etc.
^ and $ are used to match start and end of regular expressions. For e.g.
◦ ^My.*.$ will match anything starting with My and ending with a dot.
Pipe operator is used to match a string against either its left or the right
part. For e.g.
◦ (cat|dog) can match both cat or dog.
Question:
◦ If the expression is Get|GetValue|Set|SetValue and string is SetValue.
What will this match and why?
◦ What if the expression becomes Get(Value)?|Set(Value)?
* or {0,} and+ or {1,} are used to control repititions.
Round brackets besides grouping part of a regular expression
together, also create a "backreference". A backreference stores the
matching part of the string matched by the part of the regular
expression inside the parentheses. For e.g.
◦ ([0-9])1+ will match 222 but not 837.
If backreference are not required, you can optimize this regular
expression Set(?:Value)?
Backreferences can be used in expressions itself or in replacement
text. For e.g.
◦ <([A-Za-z][A-Za-z0-9]*)>.*</1>will match matching opening and closing tags.
/i makes the regex match case insensitive.
◦ [A-Z] will match A and a with this modifier.
/s enables "single-line mode". In this mode, the dot matches
newlines as well.
◦ .* will match sherazrnattari with this modifier.
/m enables "multi-line mode". In this mode, the caret and dollar
match before and after newlines in the subject string.
◦ .* will match only sherazin sherazrnattari with this modifier.
/x enables "free-spacing mode". In this mode, whitespace between
regex tokens is ignored, and an unescaped # starts a comment.
◦ #sherazrnrn.* will match only sheraz in with this modifier.
A conditional is a special construct that will first evaluate a lookaround, and then execute one
sub-regex if the lookaround succeeds, and another sub-regex if the lookaround fails.
Example of Positive lookahead is:
◦ q(?=uv*)will match q in quvvvv and qu.
Example of Negative lookahead is:
◦ q(?!uv*)will match q not followed by u and uv.
Example of Positive lookbehind is:
◦ (?<=b)awill match a prefixed by b like ba.
Example of Negative lookbehind is:
◦ (?<!b)awill match a not prefixed by b like ca and da etc.
abc… Letters
123… Digits
d Any Digit
D Any Non-digit character
. Any Character
. Period
[abc] Only a, b, or c
[^abc]Not a, b, nor c
[a-z] Characters a to z
[0-9] Numbers 0 to 9
w Any Alphanumeric character
W Any Non-alphanumeric character
{m} m Repetitions
{m,n} m to n Repetitions
* Zero or more repetitions
+ One or more repetitions
? Optional character
s Any Whitespace
S Any Non-whitespace character
^…$ Starts and ends
(…) Capture Group
(a(bc)) Capture Sub-group
(.*) Capture all
(abc|def) Matches abc or def
Most of the content is taken from
http://www.regular-expressions.info/
THANK YOU!

Contenu connexe

Similaire à Regular Expression Crash Course

Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in ActionFolio3 Software
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionskeeyre
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaj Gupta
 
Regular Expression Cheat Sheet
Regular Expression Cheat SheetRegular Expression Cheat Sheet
Regular Expression Cheat SheetSydneyJohnson57
 
Javascript正则表达式
Javascript正则表达式Javascript正则表达式
Javascript正则表达式ji guang
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlsana mateen
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionssana mateen
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular ExpressionsMukesh Tekwani
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regexwayn
 
Regex startup
Regex startupRegex startup
Regex startupPayPal
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and YouJames Armes
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20Max Kleiner
 

Similaire à Regular Expression Crash Course (20)

Regular Expression in Action
Regular Expression in ActionRegular Expression in Action
Regular Expression in Action
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expression Cheat Sheet
Regular Expression Cheat SheetRegular Expression Cheat Sheet
Regular Expression Cheat Sheet
 
Javascript正则表达式
Javascript正则表达式Javascript正则表达式
Javascript正则表达式
 
Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
2013 - Andrei Zmievski: Clínica Regex
2013 - Andrei Zmievski: Clínica Regex2013 - Andrei Zmievski: Clínica Regex
2013 - Andrei Zmievski: Clínica Regex
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
2.regular expressions
2.regular expressions2.regular expressions
2.regular expressions
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Regex startup
Regex startupRegex startup
Regex startup
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
Ruby RegEx
Ruby RegExRuby RegEx
Ruby RegEx
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and You
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 

Dernier

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
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
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
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
 
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
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 
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
 
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
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
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
 
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
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
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
 
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
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 

Dernier (20)

INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
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...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
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
 
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
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 
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
 
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
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
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
 
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
 
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
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
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)
 
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
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 

Regular Expression Crash Course

  • 1. REGULAR EXPRESSION IN ACTION Brief overview of Regular Expression building blocks and tools with a practical example
  • 2. REGULAR EXPRESSIONS PROVIDE A CONCISE AND FLEXIBLE MEANS FOR MATCHING STRINGS OF TEXT, SUCH AS PARTICULAR CHARACTERS, WORDS, OR PATTERNS OF CHARACTERS. WHAT ARE REGULAR EXPRESSIONS
  • 3. THE REGEX COACH IS A GRAPHICAL APPLICATION FOR WINDOWS WHICH CAN BE USED TO EXPERIMENT WITH REGULAR EXPRESSIONS INTERACTIVELY. ◦ http://weitz.de/regex-coach/ Sublime Text is a text editor that has support of find and replace using Regular Expressions. Web based Regular Expressions tester. ◦ http://www.regular-expressions.info/
  • 4. THE MOST BASIC REGULAR EXPRESSION CONSISTS OF A LITERAL which behaves just like string matching. For e.g. ◦ cat will match cat in About cats and dogs. Special characters known as meta characters needs to be escaped with a in regular expressions if they are used as part of a literal: ◦ dogs.will match dogs. in About cats and dogs. Meta characters are: ◦ [ ^ $ . | ? * + ( ) {
  • 5. WITH A "CHARACTER CLASS", ALSO CALLED "CHARACTER SET", YOU CAN TELL THE REGEX ENGINE TO MATCH ONLY ONE OUT OF SEVERAL CHARACTERS. FOR E.G. ◦ gr[ae]ywill match grey and gray both. Ranges can be specified using dash. For e.g. ◦ [0-9]will match any digit from 0 to 9. ◦ [0-9a-fA-F]will match any single hexadecimal digit. Caret after the opening square bracket will negate the character class. • The result is that the character class will match any character that is not • in the character class. For e.g. ◦ [^0-9] will match any thing except number. ◦ q[^u] will not match Iraq but it will match Iraq is a country
  • 6. Meta characters works fine without escaping in Character classes. For e.g. ◦ [+*]is a valid expression and match either * or +. There are some pre-defined character classes known as short hand character classes: ◦ w stands for[A-Za-z0-9_] ◦ s stands for[ trn] ◦ d stands for[0-9] If a character class is repeated by using the ?, * or + operators, the entire character class will be repeated, and not just the character that it matched. For e.g. ◦ [0-9]+ can match 837 as well as 222 ◦ ([0-9])1+ will match 222 but not 837.
  • 7. The famous dot “.” operator matches anything. For e.g. ◦ a.b will match abb, aab, a+b etc. ^ and $ are used to match start and end of regular expressions. For e.g. ◦ ^My.*.$ will match anything starting with My and ending with a dot. Pipe operator is used to match a string against either its left or the right part. For e.g. ◦ (cat|dog) can match both cat or dog. Question: ◦ If the expression is Get|GetValue|Set|SetValue and string is SetValue. What will this match and why? ◦ What if the expression becomes Get(Value)?|Set(Value)? * or {0,} and+ or {1,} are used to control repititions.
  • 8. Round brackets besides grouping part of a regular expression together, also create a "backreference". A backreference stores the matching part of the string matched by the part of the regular expression inside the parentheses. For e.g. ◦ ([0-9])1+ will match 222 but not 837. If backreference are not required, you can optimize this regular expression Set(?:Value)? Backreferences can be used in expressions itself or in replacement text. For e.g. ◦ <([A-Za-z][A-Za-z0-9]*)>.*</1>will match matching opening and closing tags.
  • 9. /i makes the regex match case insensitive. ◦ [A-Z] will match A and a with this modifier. /s enables "single-line mode". In this mode, the dot matches newlines as well. ◦ .* will match sherazrnattari with this modifier. /m enables "multi-line mode". In this mode, the caret and dollar match before and after newlines in the subject string. ◦ .* will match only sherazin sherazrnattari with this modifier. /x enables "free-spacing mode". In this mode, whitespace between regex tokens is ignored, and an unescaped # starts a comment. ◦ #sherazrnrn.* will match only sheraz in with this modifier.
  • 10. A conditional is a special construct that will first evaluate a lookaround, and then execute one sub-regex if the lookaround succeeds, and another sub-regex if the lookaround fails. Example of Positive lookahead is: ◦ q(?=uv*)will match q in quvvvv and qu. Example of Negative lookahead is: ◦ q(?!uv*)will match q not followed by u and uv. Example of Positive lookbehind is: ◦ (?<=b)awill match a prefixed by b like ba. Example of Negative lookbehind is: ◦ (?<!b)awill match a not prefixed by b like ca and da etc.
  • 11. abc… Letters 123… Digits d Any Digit D Any Non-digit character . Any Character . Period [abc] Only a, b, or c [^abc]Not a, b, nor c [a-z] Characters a to z [0-9] Numbers 0 to 9 w Any Alphanumeric character W Any Non-alphanumeric character {m} m Repetitions {m,n} m to n Repetitions * Zero or more repetitions + One or more repetitions ? Optional character s Any Whitespace S Any Non-whitespace character ^…$ Starts and ends (…) Capture Group (a(bc)) Capture Sub-group (.*) Capture all (abc|def) Matches abc or def
  • 12. Most of the content is taken from http://www.regular-expressions.info/ THANK YOU!