SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Regular Expression



What are Regular Expressions?

Regular Expressions (regex) are a way to define a
 pattern of characters in a text string.
Not all REGEX are equal


PCRE : Perl Compatible Regex

Posix : (Simple Regular Expression)
       Basic Regex (BRE)
       Extended Regex (ereg_...) (1986!)
       deprecated as of PHP 5.3.0
Components


●
  Literal Characters
●
  Character Classes
●
  Shorthand Character Classes / 'dot'
●
  Non-Printable Characters / Anchors
●
  Quantifiers
●
  Modifiers
Literal Characters



Are simple characters the way you expect
 them.
e.g. /a/ -> will match 'a' in a text
Character Classes

●
  Groups of character
    [abcdefgh0123]
●
  Range of character
    [a-h0-3]
●
  Inverse Range of Character
    [^i-z4-9]

e.g. /[gG]uide[lL]ine/ -> guideline or
 guideLine
Shorthand Char. Classes
d -> [0-9]
w -> [a-zA-Z]
s -> whitespace + [trn]

negative:
D -> [^0-9]
W -> [^a-zA-Z]
S

'.' -> any character!!
Non-printable Characters
t -> tab character (ASCII 0x09)
 r -> carriage return (0x0D)
n -> line feed (0x0A)
(a (bell, 0x07), e (escape, 0x1B), f (form feed, 0x0C) ,v (vertical
  tab, 0x0B) )

xFF -> hexadecimal index in the char. set
e.g. xA9 -> copyright symbol in the Latin-1

uFFFF -> Unicode character
e.g. u20AC -> the euro currency sign

^ begin of the string
$ end of the string
b -> word boundary - B -> not word boundary
Quantifiers
REGEXES ARE GREEDY

{min, max} / {min,} / {,max} / {exact}
? -> {0,1}
+ -> {1,}
* -> {0,}

lazy quantifiers:
carefull when using /.*/
+?
*?

| : not quantifier, simple 'OR'
Modifiers

//i : case incensitive
//m : multiline
//x : ignore whitespace

Internal Option Set:
(? .. )
(?i)
    e.g. /ab(?i)c/ -> "abc" and "abC"
Subpatterns

Pattern in a pattern in .....
Can be nested!!
e.g. /((red|white) (king|queen))/
   reg king
   white king
   red queen
   white queen
PHP & Regex


preg_.... :   PCRE
   strpos() or strstr() faster
ereg_.... :   Posix
   deprecated in 5.3.0
   preg_ is often faster
mb_ereg_...: "multibyte"
Resources & Tools

●
    http://www.regular-expressions.info
●
    http://en.wikipedia.org/wiki/Regular_expression
●
    http://be.php.net/manual/en/regexp.reference.php

●
    http://regexpal.com/
●
    http://www.fileformat.info/tool/regex.htm

●
    http://www.regexbuddy.com/
●
    http://www.ultrapico.com/Expresso.htm

Weitere ähnliche Inhalte

Was ist angesagt?

Programming in c
Programming in cProgramming in c
Programming in cvineet4523
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP StringsAhmed Swilam
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorialMohit Saini
 
Graph representation of context-free grammar
Graph representation of context-free grammarGraph representation of context-free grammar
Graph representation of context-free grammarAlex Shkotin
 
Welcome to lecture 4 in c programming
Welcome to lecture 4 in c programmingWelcome to lecture 4 in c programming
Welcome to lecture 4 in c programmingumair ansari
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageRai University
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageRai University
 
PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular ExpressionBinsent Ribera
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 

Was ist angesagt? (20)

fundamentals of c
fundamentals of cfundamentals of c
fundamentals of c
 
vim - Tips and_tricks
vim - Tips and_tricksvim - Tips and_tricks
vim - Tips and_tricks
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
Graph representation of context-free grammar
Graph representation of context-free grammarGraph representation of context-free grammar
Graph representation of context-free grammar
 
Welcome to lecture 4 in c programming
Welcome to lecture 4 in c programmingWelcome to lecture 4 in c programming
Welcome to lecture 4 in c programming
 
Parsing
ParsingParsing
Parsing
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c language
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
CSS教材
CSS教材CSS教材
CSS教材
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
Variable declaration
Variable declarationVariable declaration
Variable declaration
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
sysprog1
sysprog1sysprog1
sysprog1
 
PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular Expression
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 

Andere mochten auch

Classroom rules 2011
Classroom rules 2011Classroom rules 2011
Classroom rules 2011Liz Bennett
 
Rain Gardens, an introduction for Oregonians
Rain Gardens, an introduction for OregoniansRain Gardens, an introduction for Oregonians
Rain Gardens, an introduction for OregoniansRobert Emanuel
 
Fmeuc Presentation Hrsd3
Fmeuc Presentation Hrsd3Fmeuc Presentation Hrsd3
Fmeuc Presentation Hrsd3guest5c50492
 
Washington County Weed Watcher's training 5.10.13
Washington County Weed Watcher's training 5.10.13Washington County Weed Watcher's training 5.10.13
Washington County Weed Watcher's training 5.10.13Robert Emanuel
 
Emerald Ash Borer 11.21.13 -Wyatt Williams, ODF
Emerald Ash Borer 11.21.13 -Wyatt Williams, ODFEmerald Ash Borer 11.21.13 -Wyatt Williams, ODF
Emerald Ash Borer 11.21.13 -Wyatt Williams, ODFRobert Emanuel
 
Land use site assessment presentation 10.23.12
Land use site assessment presentation 10.23.12Land use site assessment presentation 10.23.12
Land use site assessment presentation 10.23.12Robert Emanuel
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 

Andere mochten auch (8)

Classroom rules 2011
Classroom rules 2011Classroom rules 2011
Classroom rules 2011
 
Rain Gardens, an introduction for Oregonians
Rain Gardens, an introduction for OregoniansRain Gardens, an introduction for Oregonians
Rain Gardens, an introduction for Oregonians
 
Fmeuc Presentation Hrsd3
Fmeuc Presentation Hrsd3Fmeuc Presentation Hrsd3
Fmeuc Presentation Hrsd3
 
Washington County Weed Watcher's training 5.10.13
Washington County Weed Watcher's training 5.10.13Washington County Weed Watcher's training 5.10.13
Washington County Weed Watcher's training 5.10.13
 
Geologia A Casa
Geologia A CasaGeologia A Casa
Geologia A Casa
 
Emerald Ash Borer 11.21.13 -Wyatt Williams, ODF
Emerald Ash Borer 11.21.13 -Wyatt Williams, ODFEmerald Ash Borer 11.21.13 -Wyatt Williams, ODF
Emerald Ash Borer 11.21.13 -Wyatt Williams, ODF
 
Land use site assessment presentation 10.23.12
Land use site assessment presentation 10.23.12Land use site assessment presentation 10.23.12
Land use site assessment presentation 10.23.12
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 

Ähnlich wie Regex Presentation

Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressionsmussawir20
 
Linux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxLinux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxKenny (netman)
 
How to check valid Email? Find using regex.
How to check valid Email? Find using regex.How to check valid Email? Find using regex.
How to check valid Email? Find using regex.Poznań Ruby User Group
 
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
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 
Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5bilcorry
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracleLogan Palanisamy
 
Parsing Expression Grammars
Parsing Expression GrammarsParsing Expression Grammars
Parsing Expression Grammarsteknico
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++ Samsil Arefin
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashessana mateen
 
Regular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondMax Shirshin
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionskeeyre
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007Geoffrey Dunn
 

Ähnlich wie Regex Presentation (20)

Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
 
Quick start reg ex
Quick start reg exQuick start reg ex
Quick start reg ex
 
Ruby RegEx
Ruby RegExRuby RegEx
Ruby RegEx
 
Linux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxLinux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regx
 
How to check valid Email? Find using regex.
How to check valid Email? Find using regex.How to check valid Email? Find using regex.
How to check valid Email? Find using regex.
 
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
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Reg EX
Reg EXReg EX
Reg EX
 
Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5Introduction To Regex in Lasso 8.5
Introduction To Regex in Lasso 8.5
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
Parsing Expression Grammars
Parsing Expression GrammarsParsing Expression Grammars
Parsing Expression Grammars
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashes
 
Regular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And Beyond
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expressions 2007
Regular Expressions 2007Regular Expressions 2007
Regular Expressions 2007
 

Kürzlich hochgeladen

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Regex Presentation

  • 1. Regular Expression What are Regular Expressions? Regular Expressions (regex) are a way to define a pattern of characters in a text string.
  • 2. Not all REGEX are equal PCRE : Perl Compatible Regex Posix : (Simple Regular Expression) Basic Regex (BRE) Extended Regex (ereg_...) (1986!) deprecated as of PHP 5.3.0
  • 3. Components ● Literal Characters ● Character Classes ● Shorthand Character Classes / 'dot' ● Non-Printable Characters / Anchors ● Quantifiers ● Modifiers
  • 4. Literal Characters Are simple characters the way you expect them. e.g. /a/ -> will match 'a' in a text
  • 5. Character Classes ● Groups of character [abcdefgh0123] ● Range of character [a-h0-3] ● Inverse Range of Character [^i-z4-9] e.g. /[gG]uide[lL]ine/ -> guideline or guideLine
  • 6. Shorthand Char. Classes d -> [0-9] w -> [a-zA-Z] s -> whitespace + [trn] negative: D -> [^0-9] W -> [^a-zA-Z] S '.' -> any character!!
  • 7. Non-printable Characters t -> tab character (ASCII 0x09) r -> carriage return (0x0D) n -> line feed (0x0A) (a (bell, 0x07), e (escape, 0x1B), f (form feed, 0x0C) ,v (vertical tab, 0x0B) ) xFF -> hexadecimal index in the char. set e.g. xA9 -> copyright symbol in the Latin-1 uFFFF -> Unicode character e.g. u20AC -> the euro currency sign ^ begin of the string $ end of the string b -> word boundary - B -> not word boundary
  • 8. Quantifiers REGEXES ARE GREEDY {min, max} / {min,} / {,max} / {exact} ? -> {0,1} + -> {1,} * -> {0,} lazy quantifiers: carefull when using /.*/ +? *? | : not quantifier, simple 'OR'
  • 9. Modifiers //i : case incensitive //m : multiline //x : ignore whitespace Internal Option Set: (? .. ) (?i) e.g. /ab(?i)c/ -> "abc" and "abC"
  • 10. Subpatterns Pattern in a pattern in ..... Can be nested!! e.g. /((red|white) (king|queen))/ reg king white king red queen white queen
  • 11. PHP & Regex preg_.... : PCRE strpos() or strstr() faster ereg_.... : Posix deprecated in 5.3.0 preg_ is often faster mb_ereg_...: "multibyte"
  • 12. Resources & Tools ● http://www.regular-expressions.info ● http://en.wikipedia.org/wiki/Regular_expression ● http://be.php.net/manual/en/regexp.reference.php ● http://regexpal.com/ ● http://www.fileformat.info/tool/regex.htm ● http://www.regexbuddy.com/ ● http://www.ultrapico.com/Expresso.htm