SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Último (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 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