SlideShare una empresa de 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

Más contenido relacionado

La actualidad más candente

PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular Expression
Binsent Ribera
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 

La actualidad más candente (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
 

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

Similar a Regex Presentation

Php String And Regular Expressions
Php String  And Regular ExpressionsPhp String  And Regular Expressions
Php String And Regular Expressions
mussawir20
 

Similar 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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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