SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
Tim Gremalm
Developer at Conmel Data AB
Programming, Web, Databases, Windows/Linux, Servers,
Network, TCP/IP, Robotics, Electronics

tim@gremalm.se
http://tim.gremalm.se

Lecture - Regular expression (Tim Gremalm)
Regular expression
●

A string that forms a searchpattern

●

The basics of regex started in the 1950's

●

Used in many UNIX-tools like grep, ed, awk

●

Most programming languages supports regular expressions

●

Also called regex, regexp

Lecture - Regular expression (Tim Gremalm)
Common uses of regular expression
●

Match a text with a searchpattern for validation

●

Search replace (substitute) text

●

Syntax-highlighting in editors

●

Extracting relevant parts of a text

Lecture - Regular expression (Tim Gremalm)
Regular expression
Match literary

Special Characters


Carriage return +
Tab +

v

Vertical tab +

f

Form feed +

a

Alarm

[b]

Backspace

e

Escape

N{name}

Lecture - Regular expression (Tim Gremalm)

New line +

t

Just enter you text like:
yoursearchterm

n
r

●

Escape Character +

Named Character
Regular expression
Anchors
●

Position your search term

Anchors
^

End of string +
Word boundary +
Not word boundary +
Start of word

>

Lecture - Regular expression (Tim Gremalm)

End of line +

<

bStartOfWord

$

B

●

Start of string +

b

^StartOfLine

A

Z

●

Start of line +

End of word
Regular expression
Character Classes
Character Classes

●

Specify a [class] to search for

Control character

s

White space

S

Not white space

d

Digit

D

Not digit

w

Word

W

Not word

xhh

Hexadecimal character hh

Oxxx

Lecture - Regular expression (Tim Gremalm)

c

Octal character xxx
Regular expression
Quantifiers

Quantifiers
*

Lecture - Regular expression (Tim Gremalm)

1 or more, ungreedy +
0 or 1 +
0 or 1, ungreedy +
Exactly 3 +
3 or more +
3, 4 or 5 +

{3,5}?

l*

+?

{3,5}

●

1 or more +

{3,}

[d]+

+

{3}

●

0 or more, ungreedy +

??

Specify how many times a class may occur

*?

?

●

0 or more +

3, 4 or 5, ungreedy +
Regular expression
Ranges

Ranges
.

Lecture - Regular expression (Tim Gremalm)

[abc]

Range (a or b or c) +
Not a or b or c +
Letter between a and q +
Upper case letter +
between A and Q +
Digit between 0 and 7 +

n

[a-zA-Z]

Passive Group +

[0-7]

●

Group +

[A-Q]

[A-E]

(...)

[a-q]

●

a or b +

[^abc]

Specify a class even further

(a|b)

(?:...)

●

Any character except new line (n) +

nth group/subpattern +
Regular expression
Groups
●

Extract several parts of a text at the same time

●

^(.*).(.*)$

●

(filename).(Fileextension)

Lecture - Regular expression (Tim Gremalm)
Links
●

http://regex101.com/ - Online regex parser

●

http://regexpal.com/ - Online regex parser

●

http://gskinner.com/RegExr/ - Online regex parser

●

http://www.txt2re.com/ - Help you build regex

●

http://www.myezapp.com/apps/dev/regexp/show.ws - Help you analyze the regex-syntax in words

Lecture - Regular expression (Tim Gremalm)

Contenu connexe

Tendances

Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrepTri Truong
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expressionGagan019
 
Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Ben Brumfield
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsJesse Anderson
 
Application of hashing in better alg design tanmay
Application of hashing in better alg design tanmayApplication of hashing in better alg design tanmay
Application of hashing in better alg design tanmayTanmay 'Unsinkable'
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressionsYamagata Europe
 

Tendances (7)

Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Application of hashing in better alg design tanmay
Application of hashing in better alg design tanmayApplication of hashing in better alg design tanmay
Application of hashing in better alg design tanmay
 
An Introduction to Regular expressions
An Introduction to Regular expressionsAn Introduction to Regular expressions
An Introduction to Regular expressions
 

Similaire à Kodar-lan - Text and editors Regular expression

Similaire à Kodar-lan - Text and editors Regular expression (20)

Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions
 
Basta mastering regex power
Basta mastering regex powerBasta mastering regex power
Basta mastering regex power
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and You
 
Don't Fear the Regex LSP15
Don't Fear the Regex LSP15Don't Fear the Regex LSP15
Don't Fear the Regex LSP15
 
Don't Fear the Regex WordCamp DC 2017
Don't Fear the Regex WordCamp DC 2017Don't Fear the Regex WordCamp DC 2017
Don't Fear the Regex WordCamp DC 2017
 
algo1-aa-gist_typed.pdf
algo1-aa-gist_typed.pdfalgo1-aa-gist_typed.pdf
algo1-aa-gist_typed.pdf
 
test vedio
test vediotest vedio
test vedio
 
qwdeqwe
qwdeqweqwdeqwe
qwdeqwe
 
Added to test pdf
Added to test pdf Added to test pdf
Added to test pdf
 
added for test
added for test added for test
added for test
 
ganesh testing
ganesh testing ganesh testing
ganesh testing
 
now its pdf
now its pdfnow its pdf
now its pdf
 
fghfghf
fghfghffghfghf
fghfghf
 
The hindu
The hinduThe hindu
The hindu
 
Video added by Normal user
Video added by Normal user Video added by Normal user
Video added by Normal user
 
Resource one
Resource one Resource one
Resource one
 
Added to test pdf
Added to test pdf Added to test pdf
Added to test pdf
 
dasdasd
dasdasddasdasd
dasdasd
 
estset
estsetestset
estset
 
1377874234 eeeeeeeeeeeeeeeor more file
1377874234 eeeeeeeeeeeeeeeor more file1377874234 eeeeeeeeeeeeeeeor more file
1377874234 eeeeeeeeeeeeeeeor more file
 

Dernier

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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Dernier (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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 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
 
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
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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...
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Kodar-lan - Text and editors Regular expression

  • 1. Tim Gremalm Developer at Conmel Data AB Programming, Web, Databases, Windows/Linux, Servers, Network, TCP/IP, Robotics, Electronics tim@gremalm.se http://tim.gremalm.se Lecture - Regular expression (Tim Gremalm)
  • 2. Regular expression ● A string that forms a searchpattern ● The basics of regex started in the 1950's ● Used in many UNIX-tools like grep, ed, awk ● Most programming languages supports regular expressions ● Also called regex, regexp Lecture - Regular expression (Tim Gremalm)
  • 3. Common uses of regular expression ● Match a text with a searchpattern for validation ● Search replace (substitute) text ● Syntax-highlighting in editors ● Extracting relevant parts of a text Lecture - Regular expression (Tim Gremalm)
  • 4. Regular expression Match literary Special Characters Carriage return + Tab + v Vertical tab + f Form feed + a Alarm [b] Backspace e Escape N{name} Lecture - Regular expression (Tim Gremalm) New line + t Just enter you text like: yoursearchterm n r ● Escape Character + Named Character
  • 5. Regular expression Anchors ● Position your search term Anchors ^ End of string + Word boundary + Not word boundary + Start of word > Lecture - Regular expression (Tim Gremalm) End of line + < bStartOfWord $ B ● Start of string + b ^StartOfLine A Z ● Start of line + End of word
  • 6. Regular expression Character Classes Character Classes ● Specify a [class] to search for Control character s White space S Not white space d Digit D Not digit w Word W Not word xhh Hexadecimal character hh Oxxx Lecture - Regular expression (Tim Gremalm) c Octal character xxx
  • 7. Regular expression Quantifiers Quantifiers * Lecture - Regular expression (Tim Gremalm) 1 or more, ungreedy + 0 or 1 + 0 or 1, ungreedy + Exactly 3 + 3 or more + 3, 4 or 5 + {3,5}? l* +? {3,5} ● 1 or more + {3,} [d]+ + {3} ● 0 or more, ungreedy + ?? Specify how many times a class may occur *? ? ● 0 or more + 3, 4 or 5, ungreedy +
  • 8. Regular expression Ranges Ranges . Lecture - Regular expression (Tim Gremalm) [abc] Range (a or b or c) + Not a or b or c + Letter between a and q + Upper case letter + between A and Q + Digit between 0 and 7 + n [a-zA-Z] Passive Group + [0-7] ● Group + [A-Q] [A-E] (...) [a-q] ● a or b + [^abc] Specify a class even further (a|b) (?:...) ● Any character except new line (n) + nth group/subpattern +
  • 9. Regular expression Groups ● Extract several parts of a text at the same time ● ^(.*).(.*)$ ● (filename).(Fileextension) Lecture - Regular expression (Tim Gremalm)
  • 10. Links ● http://regex101.com/ - Online regex parser ● http://regexpal.com/ - Online regex parser ● http://gskinner.com/RegExr/ - Online regex parser ● http://www.txt2re.com/ - Help you build regex ● http://www.myezapp.com/apps/dev/regexp/show.ws - Help you analyze the regex-syntax in words Lecture - Regular expression (Tim Gremalm)