SlideShare uma empresa Scribd logo
1 de 20
Regular expression (RE)
- crash course
door Daniel Genis, Byte Internet
Regex - What is a regular expression
- A mini program accepts or rejects a string.
- Can be used to parse data out of strings
Regex - Why regular expressions?
PRO
● Parsing is fast O(n) + NFA generation time
○ NFA generation time is a one time penalty
○ For a RE of size m we can build an NFA at a cost of
O(2^m)
● Useful for validating string input
● Can be used in all Programming languages
○ Even in MySQL or other databases. But please
please don’t use RE in database queries :-)
● Useful for fetching/parsing data out of strings
● Very powerful tool. A real swiss army knife!
Regex - When to avoid RE?
CONS
● Regexes are a mini programs in themselves
● They can become very complex
● Some people argue regexes should always be avoided
● They are not very human readable
● Not everyone is comfortable with RE
● DFA must be created/compiled initially
Regex - Getting a feel
Two dummy examples
^aap?$
a()?p+p
Real world example:
DB_BACKUP_REGEX = "^[a-zA-Z0-9_-]+_((d|-)+_(d|-
)+)_UTC.sql.gz$"
Regex - Semantic buildingblocks
‘.’ == Matches any character except a newline
‘^’ == Matches the start of the string
‘$’ == Matches the end of a string
‘*’ == Causes the resulting RE to match 0 or more repetitions
‘+’ == Causes the resulting RE to match 1 or more repetitions
‘?’ == Causes the resulting RE to match 0 or 1 repetitions
Regex - basics - Which string matches?
Regex: ^a(ab)*b$
Strings:
aaab
aabb
ab
abbb
aababb
_aabb _ == whitespace
aabb_
Regex - basics - ^ () * $
Regex: ^a(ab)*b$
Strings:
aaab
aabb
ab
abbb
aababb
_aabb _ == whitespace
aabb_
Regex - basics - ^ () * $
Regex: ^a(ab)*b$
Strings:
aaab
aabb
ab
abbb
aababb
_aabb
aabb_
Regex - basics - Which string matches?
Regex: aa+b*b$ old regex: ^a(ab)*b$
Strings:
aaab
aabb
ab
abbb
aababb
_aabb _ == whitespace
aabb_
Regex - basics - Which string matches?
Regex: aa+b*b$ old regex: ^a(ab)*b$
Strings:
aaab
aabb
ab
abbb
aababa
_aabb
aabb_
Regex - basics - Which string matches?
Regex: aa+b*b$ old regex: ^a(ab)*b$
Strings:
aaab
aabb
ab
abbb
aababa
_aabb
aabb_
Regex - some more buildingblocks
[a-zA-Z0-9] == w
Matches 1 character a-z or A-Z or 0-9.
and is the same as w
d == [0-9]
Matches 1 number
d{5}
Matches 5 numbers
Regex - bad practical example
import re
data = “2014-06-04 20:00”
# How do we parse this to integers?
regex = “^(d{4})-(d{2})-(d{2}) (d{2}):(d{2})”
regex2 = “(d+)-(d+)-(d+) (d+):(d+)” # Works too!
re.findall(regex, data)
# returns
Regex - regex DFA
regex2 =
“(d+)-(d+)-(d+) (d+):(d+)”
Regex - stuff we didn’t cover! :D
Regex can get very very complicated.
Just to give you some idea:
- Lookahead assertion
(?=...)
Matches if ... matches next, but doesn’t consume any of the
string. This is called a lookahead assertion. For example, Isaac
(?=Asimov) will match 'Isaac ' only if it’s followed by 'Asimov'.
For example: (Isaac (?=Asimov))|(Banaan)
Will match ‘Isaac Asimov’ or ‘Banaan’
Regex - stuff we didn’t cover! :D
- Greedy vs Non-Greedy
‘*’, ‘+’, ‘?’ are greedy quanitifiers. They will match as much
as possible to obtain a match.
Non greedy quanitfiers will match as little as possible to
achieve a match.
Adding a ‘?’ makes the above quantifiers non-greedy
‘*?’, ‘+?’, ‘??’
We’ll skip these 2 for now :-)
- Positive lookbehind assertion
Greedy vs Non-greedy example
string = abbb
regex = ab+?
matches = abbb
regex = ab+
matches = abbb
regex = ab+?$
matches = abbb
Vragen
?
Regex - Usefull tools!
Regex -> NFA/DFA converter
http://hackingoff.com/compilers/regular-expression-to-nfa-dfa
Testing regexes yourself
http://www.pythonregex.com/

Mais conteúdo relacionado

Mais procurados

The last decade of RWiki and lazy me.
The last decade of RWiki and lazy me.The last decade of RWiki and lazy me.
The last decade of RWiki and lazy me.mseki
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Robert Schadek
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetAndrei Alexandrescu
 
Parallel computing with GPars
Parallel computing with GParsParallel computing with GPars
Parallel computing with GParsPablo Molnar
 
Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)Fabio Akita
 
Lisp for Python Programmers
Lisp for Python ProgrammersLisp for Python Programmers
Lisp for Python ProgrammersVsevolod Dyomkin
 
Gaucheで本を作る
Gaucheで本を作るGaucheで本を作る
Gaucheで本を作るguest7a66b8
 
A Very Brief Intro to Golang
A Very Brief Intro to GolangA Very Brief Intro to Golang
A Very Brief Intro to GolangJoshua Haupt
 

Mais procurados (10)

Elastic @Deezer
Elastic @DeezerElastic @Deezer
Elastic @Deezer
 
The last decade of RWiki and lazy me.
The last decade of RWiki and lazy me.The last decade of RWiki and lazy me.
The last decade of RWiki and lazy me.
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
 
Parallel computing with GPars
Parallel computing with GParsParallel computing with GPars
Parallel computing with GPars
 
Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)
 
Lisp for Python Programmers
Lisp for Python ProgrammersLisp for Python Programmers
Lisp for Python Programmers
 
Swift and the BigData
Swift and the BigDataSwift and the BigData
Swift and the BigData
 
Gaucheで本を作る
Gaucheで本を作るGaucheで本を作る
Gaucheで本を作る
 
A Very Brief Intro to Golang
A Very Brief Intro to GolangA Very Brief Intro to Golang
A Very Brief Intro to Golang
 

Destaque

Google Webmasters Tools
Google Webmasters ToolsGoogle Webmasters Tools
Google Webmasters ToolsByte
 
Beaumotica.com & Magento 2 - Meet Magento 2016
Beaumotica.com & Magento 2 -  Meet Magento 2016Beaumotica.com & Magento 2 -  Meet Magento 2016
Beaumotica.com & Magento 2 - Meet Magento 2016Byte
 
Hackers traced - Meet Magento 2016
Hackers traced -  Meet Magento 2016Hackers traced -  Meet Magento 2016
Hackers traced - Meet Magento 2016Byte
 
Presentatie snelheid ecl
Presentatie snelheid eclPresentatie snelheid ecl
Presentatie snelheid eclByte
 
Workshop New Relic - juni 2015
Workshop New Relic - juni 2015Workshop New Relic - juni 2015
Workshop New Relic - juni 2015Byte
 
Magento 2 performance - a benchmark
Magento 2 performance - a benchmarkMagento 2 performance - a benchmark
Magento 2 performance - a benchmarkByte
 

Destaque (6)

Google Webmasters Tools
Google Webmasters ToolsGoogle Webmasters Tools
Google Webmasters Tools
 
Beaumotica.com & Magento 2 - Meet Magento 2016
Beaumotica.com & Magento 2 -  Meet Magento 2016Beaumotica.com & Magento 2 -  Meet Magento 2016
Beaumotica.com & Magento 2 - Meet Magento 2016
 
Hackers traced - Meet Magento 2016
Hackers traced -  Meet Magento 2016Hackers traced -  Meet Magento 2016
Hackers traced - Meet Magento 2016
 
Presentatie snelheid ecl
Presentatie snelheid eclPresentatie snelheid ecl
Presentatie snelheid ecl
 
Workshop New Relic - juni 2015
Workshop New Relic - juni 2015Workshop New Relic - juni 2015
Workshop New Relic - juni 2015
 
Magento 2 performance - a benchmark
Magento 2 performance - a benchmarkMagento 2 performance - a benchmark
Magento 2 performance - a benchmark
 

Semelhante a Regex - Crash course on regular expressions

Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeProf. Wim Van Criekinge
 
New features in abap
New features in abapNew features in abap
New features in abapSrihari J
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsEran Zimbler
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica"FENG "GEORGE"" YU
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
Perly Parsing with Regexp::Grammars
Perly Parsing with Regexp::GrammarsPerly Parsing with Regexp::Grammars
Perly Parsing with Regexp::GrammarsWorkhorse Computing
 
27.2.9 lab regular expression tutorial
27.2.9 lab   regular expression tutorial27.2.9 lab   regular expression tutorial
27.2.9 lab regular expression tutorialFreddy Buenaño
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Andrea Telatin
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/ibrettflorio
 
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...openCypher
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptxNiladriDey18
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionskeeyre
 

Semelhante a Regex - Crash course on regular expressions (20)

Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Regexes in .NET
Regexes in .NETRegexes in .NET
Regexes in .NET
 
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
 
CL-NLP
CL-NLPCL-NLP
CL-NLP
 
New features in abap
New features in abapNew features in abap
New features in abap
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Query Optimization - Brandon Latronica
Query Optimization - Brandon LatronicaQuery Optimization - Brandon Latronica
Query Optimization - Brandon Latronica
 
Regular expression for everyone
Regular expression for everyoneRegular expression for everyone
Regular expression for everyone
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Perly Parsing with Regexp::Grammars
Perly Parsing with Regexp::GrammarsPerly Parsing with Regexp::Grammars
Perly Parsing with Regexp::Grammars
 
27.2.9 lab regular expression tutorial
27.2.9 lab   regular expression tutorial27.2.9 lab   regular expression tutorial
27.2.9 lab regular expression tutorial
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
Bioinformatica: Esercizi su Perl, espressioni regolari e altre amenità (BMR G...
 
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
/Regex makes me want to (weep|give up|(╯°□°)╯︵ ┻━┻)\.?/i
 
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
 
User biglm
User biglmUser biglm
User biglm
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 

Mais de Byte

Hypernode Pitch @ Meet Magento 2014
Hypernode Pitch @ Meet Magento 2014Hypernode Pitch @ Meet Magento 2014
Hypernode Pitch @ Meet Magento 2014Byte
 
Joomladagen 2014 - Google Tag Manager
Joomladagen 2014 - Google Tag ManagerJoomladagen 2014 - Google Tag Manager
Joomladagen 2014 - Google Tag ManagerByte
 
Hexagonal Design - Maarten van Schaik
Hexagonal Design - Maarten van SchaikHexagonal Design - Maarten van Schaik
Hexagonal Design - Maarten van SchaikByte
 
Exception Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim MullerException Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim MullerByte
 
Presentatie MUG 27 juni 2013 - Graphite/New Relic
Presentatie MUG 27 juni 2013 - Graphite/New RelicPresentatie MUG 27 juni 2013 - Graphite/New Relic
Presentatie MUG 27 juni 2013 - Graphite/New RelicByte
 
Mm13 nl presentatie byte
Mm13 nl presentatie byteMm13 nl presentatie byte
Mm13 nl presentatie byteByte
 
Site gehacked... hoe op te lossen?
 Site gehacked... hoe op te lossen? Site gehacked... hoe op te lossen?
Site gehacked... hoe op te lossen?Byte
 
Varnish & Magento
Varnish & MagentoVarnish & Magento
Varnish & MagentoByte
 
Redis - Magento User Group
Redis - Magento User GroupRedis - Magento User Group
Redis - Magento User GroupByte
 
Help! My site has been hacked!
Help! My site has been hacked!Help! My site has been hacked!
Help! My site has been hacked!Byte
 
Byte hackpreventie
Byte hackpreventieByte hackpreventie
Byte hackpreventieByte
 
Magento Speed Analysis - Meet Magento 2012
Magento Speed Analysis - Meet Magento 2012Magento Speed Analysis - Meet Magento 2012
Magento Speed Analysis - Meet Magento 2012Byte
 
Hosting & Onderhoud Joomladagen 2012
Hosting & Onderhoud Joomladagen 2012Hosting & Onderhoud Joomladagen 2012
Hosting & Onderhoud Joomladagen 2012Byte
 
10 Joomla vragen - Joomladagen 2010
10 Joomla vragen - Joomladagen 201010 Joomla vragen - Joomladagen 2010
10 Joomla vragen - Joomladagen 2010Byte
 
Magento Hosting, Performance & Stabiliteit - Meet Magento 2011
Magento Hosting, Performance & Stabiliteit - Meet Magento 2011Magento Hosting, Performance & Stabiliteit - Meet Magento 2011
Magento Hosting, Performance & Stabiliteit - Meet Magento 2011Byte
 
Google analytics - Joomladagen2012
Google analytics - Joomladagen2012Google analytics - Joomladagen2012
Google analytics - Joomladagen2012Byte
 
Magento Mobile - Byte Seminar
Magento Mobile - Byte SeminarMagento Mobile - Byte Seminar
Magento Mobile - Byte SeminarByte
 

Mais de Byte (17)

Hypernode Pitch @ Meet Magento 2014
Hypernode Pitch @ Meet Magento 2014Hypernode Pitch @ Meet Magento 2014
Hypernode Pitch @ Meet Magento 2014
 
Joomladagen 2014 - Google Tag Manager
Joomladagen 2014 - Google Tag ManagerJoomladagen 2014 - Google Tag Manager
Joomladagen 2014 - Google Tag Manager
 
Hexagonal Design - Maarten van Schaik
Hexagonal Design - Maarten van SchaikHexagonal Design - Maarten van Schaik
Hexagonal Design - Maarten van Schaik
 
Exception Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim MullerException Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim Muller
 
Presentatie MUG 27 juni 2013 - Graphite/New Relic
Presentatie MUG 27 juni 2013 - Graphite/New RelicPresentatie MUG 27 juni 2013 - Graphite/New Relic
Presentatie MUG 27 juni 2013 - Graphite/New Relic
 
Mm13 nl presentatie byte
Mm13 nl presentatie byteMm13 nl presentatie byte
Mm13 nl presentatie byte
 
Site gehacked... hoe op te lossen?
 Site gehacked... hoe op te lossen? Site gehacked... hoe op te lossen?
Site gehacked... hoe op te lossen?
 
Varnish & Magento
Varnish & MagentoVarnish & Magento
Varnish & Magento
 
Redis - Magento User Group
Redis - Magento User GroupRedis - Magento User Group
Redis - Magento User Group
 
Help! My site has been hacked!
Help! My site has been hacked!Help! My site has been hacked!
Help! My site has been hacked!
 
Byte hackpreventie
Byte hackpreventieByte hackpreventie
Byte hackpreventie
 
Magento Speed Analysis - Meet Magento 2012
Magento Speed Analysis - Meet Magento 2012Magento Speed Analysis - Meet Magento 2012
Magento Speed Analysis - Meet Magento 2012
 
Hosting & Onderhoud Joomladagen 2012
Hosting & Onderhoud Joomladagen 2012Hosting & Onderhoud Joomladagen 2012
Hosting & Onderhoud Joomladagen 2012
 
10 Joomla vragen - Joomladagen 2010
10 Joomla vragen - Joomladagen 201010 Joomla vragen - Joomladagen 2010
10 Joomla vragen - Joomladagen 2010
 
Magento Hosting, Performance & Stabiliteit - Meet Magento 2011
Magento Hosting, Performance & Stabiliteit - Meet Magento 2011Magento Hosting, Performance & Stabiliteit - Meet Magento 2011
Magento Hosting, Performance & Stabiliteit - Meet Magento 2011
 
Google analytics - Joomladagen2012
Google analytics - Joomladagen2012Google analytics - Joomladagen2012
Google analytics - Joomladagen2012
 
Magento Mobile - Byte Seminar
Magento Mobile - Byte SeminarMagento Mobile - Byte Seminar
Magento Mobile - Byte Seminar
 

Último

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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...Drew Madelung
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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 2024Rafal Los
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
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 StreamsRoshan Dwivedi
 
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...Neo4j
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 

Último (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
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
 
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...
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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...
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 

Regex - Crash course on regular expressions

  • 1. Regular expression (RE) - crash course door Daniel Genis, Byte Internet
  • 2. Regex - What is a regular expression - A mini program accepts or rejects a string. - Can be used to parse data out of strings
  • 3. Regex - Why regular expressions? PRO ● Parsing is fast O(n) + NFA generation time ○ NFA generation time is a one time penalty ○ For a RE of size m we can build an NFA at a cost of O(2^m) ● Useful for validating string input ● Can be used in all Programming languages ○ Even in MySQL or other databases. But please please don’t use RE in database queries :-) ● Useful for fetching/parsing data out of strings ● Very powerful tool. A real swiss army knife!
  • 4. Regex - When to avoid RE? CONS ● Regexes are a mini programs in themselves ● They can become very complex ● Some people argue regexes should always be avoided ● They are not very human readable ● Not everyone is comfortable with RE ● DFA must be created/compiled initially
  • 5. Regex - Getting a feel Two dummy examples ^aap?$ a()?p+p Real world example: DB_BACKUP_REGEX = "^[a-zA-Z0-9_-]+_((d|-)+_(d|- )+)_UTC.sql.gz$"
  • 6. Regex - Semantic buildingblocks ‘.’ == Matches any character except a newline ‘^’ == Matches the start of the string ‘$’ == Matches the end of a string ‘*’ == Causes the resulting RE to match 0 or more repetitions ‘+’ == Causes the resulting RE to match 1 or more repetitions ‘?’ == Causes the resulting RE to match 0 or 1 repetitions
  • 7. Regex - basics - Which string matches? Regex: ^a(ab)*b$ Strings: aaab aabb ab abbb aababb _aabb _ == whitespace aabb_
  • 8. Regex - basics - ^ () * $ Regex: ^a(ab)*b$ Strings: aaab aabb ab abbb aababb _aabb _ == whitespace aabb_
  • 9. Regex - basics - ^ () * $ Regex: ^a(ab)*b$ Strings: aaab aabb ab abbb aababb _aabb aabb_
  • 10. Regex - basics - Which string matches? Regex: aa+b*b$ old regex: ^a(ab)*b$ Strings: aaab aabb ab abbb aababb _aabb _ == whitespace aabb_
  • 11. Regex - basics - Which string matches? Regex: aa+b*b$ old regex: ^a(ab)*b$ Strings: aaab aabb ab abbb aababa _aabb aabb_
  • 12. Regex - basics - Which string matches? Regex: aa+b*b$ old regex: ^a(ab)*b$ Strings: aaab aabb ab abbb aababa _aabb aabb_
  • 13. Regex - some more buildingblocks [a-zA-Z0-9] == w Matches 1 character a-z or A-Z or 0-9. and is the same as w d == [0-9] Matches 1 number d{5} Matches 5 numbers
  • 14. Regex - bad practical example import re data = “2014-06-04 20:00” # How do we parse this to integers? regex = “^(d{4})-(d{2})-(d{2}) (d{2}):(d{2})” regex2 = “(d+)-(d+)-(d+) (d+):(d+)” # Works too! re.findall(regex, data) # returns
  • 15. Regex - regex DFA regex2 = “(d+)-(d+)-(d+) (d+):(d+)”
  • 16. Regex - stuff we didn’t cover! :D Regex can get very very complicated. Just to give you some idea: - Lookahead assertion (?=...) Matches if ... matches next, but doesn’t consume any of the string. This is called a lookahead assertion. For example, Isaac (?=Asimov) will match 'Isaac ' only if it’s followed by 'Asimov'. For example: (Isaac (?=Asimov))|(Banaan) Will match ‘Isaac Asimov’ or ‘Banaan’
  • 17. Regex - stuff we didn’t cover! :D - Greedy vs Non-Greedy ‘*’, ‘+’, ‘?’ are greedy quanitifiers. They will match as much as possible to obtain a match. Non greedy quanitfiers will match as little as possible to achieve a match. Adding a ‘?’ makes the above quantifiers non-greedy ‘*?’, ‘+?’, ‘??’ We’ll skip these 2 for now :-) - Positive lookbehind assertion
  • 18. Greedy vs Non-greedy example string = abbb regex = ab+? matches = abbb regex = ab+ matches = abbb regex = ab+?$ matches = abbb
  • 20. Regex - Usefull tools! Regex -> NFA/DFA converter http://hackingoff.com/compilers/regular-expression-to-nfa-dfa Testing regexes yourself http://www.pythonregex.com/