SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Regular Expressions in Java
Regular Expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Perl and Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A first example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Doing it in Perl and Ruby ,[object Object],[object Object],[object Object],[object Object],[object Object]
Doing it in Java, I ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Doing it in Java, II ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Finding what was matched ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A complete example import java.util.regex.*;   public class RegexTest {   public static void main(String args[]) {   String pattern = "[a-z]+";   String text = "Now is the time";   Pattern p = Pattern.compile(pattern);   Matcher m = p.matcher(text);   while (m.find()) {   System.out.print(text.substring ( m.start(), m.end() )  + "*");   }   } } Output:  ow*is*the*time*
Additional methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Some simple patterns ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sequences and alternatives ,[object Object],[object Object],[object Object],[object Object]
Some predefined character classes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Notice the space. Spaces are  significant in regular expressions!
Boundary matchers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Greedy quantifiers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Types of quantifiers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Quantifier examples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Capturing groups ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Capturing groups in Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example use of capturing groups ,[object Object],[object Object],[object Object],[object Object]
Double backslashes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Escaping metacharacters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Spaces ,[object Object],[object Object],[object Object],[object Object]
Additions to the  String  class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thinking in regular expressions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The End “ A little learning is a dangerous thing;   drink deep, or taste not the Pierian spring:   there shallow draughts intoxicate the brain,   and drinking largely sobers us again.”   --Alexander Pope

Weitere ähnliche Inhalte

Was ist angesagt?

Regular expressions
Regular expressionsRegular expressions
Regular expressions
Raj Gupta
 
Python advanced 2. regular expression in python
Python advanced 2. regular expression in pythonPython advanced 2. regular expression in python
Python advanced 2. regular expression in python
John(Qiang) Zhang
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
arnolambert
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
Amrit Kaur
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
Tri Truong
 

Was ist angesagt? (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Python advanced 2. regular expression in python
Python advanced 2. regular expression in pythonPython advanced 2. regular expression in python
Python advanced 2. regular expression in python
 
Andrei's Regex Clinic
Andrei's Regex ClinicAndrei's Regex Clinic
Andrei's Regex Clinic
 
Python (regular expression)
Python (regular expression)Python (regular expression)
Python (regular expression)
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
Regular expressions in Ruby and Introduction to Vim
Regular expressions in Ruby and Introduction to VimRegular expressions in Ruby and Introduction to Vim
Regular expressions in Ruby and Introduction to Vim
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) Fundamentals
 
Regular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular ExpressionsRegular Expressions 101 Introduction to Regular Expressions
Regular Expressions 101 Introduction to Regular Expressions
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Python strings
Python stringsPython strings
Python strings
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Regular expression examples
Regular expression examplesRegular expression examples
Regular expression examples
 

Andere mochten auch (7)

enums
enumsenums
enums
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
Regexp master 2011
Regexp master 2011Regexp master 2011
Regexp master 2011
 
Expresiones regulares
Expresiones regularesExpresiones regulares
Expresiones regulares
 
Java GC
Java GCJava GC
Java GC
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1
 
Java I/O
Java I/OJava I/O
Java I/O
 

Ähnlich wie 16 Java Regex

Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Raghu nath
 
PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular Expression
Binsent Ribera
 
Lecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdfLecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdf
Saravana Kumar
 

Ähnlich wie 16 Java Regex (20)

M C6java7
M C6java7M C6java7
M C6java7
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptx
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
regular-expression.pdf
regular-expression.pdfregular-expression.pdf
regular-expression.pdf
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
 
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
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 
Regex startup
Regex startupRegex startup
Regex startup
 
PERL Regular Expression
PERL Regular ExpressionPERL Regular Expression
PERL Regular Expression
 
Lecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdfLecture 18 - Regular Expressions.pdf
Lecture 18 - Regular Expressions.pdf
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introduction
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
Python - Lecture 7
Python - Lecture 7Python - Lecture 7
Python - Lecture 7
 
Les08
Les08Les08
Les08
 

Mehr von wayn

Orissa Riots
Orissa RiotsOrissa Riots
Orissa Riots
wayn
 
Global Warmin Powerpoint
Global Warmin PowerpointGlobal Warmin Powerpoint
Global Warmin Powerpoint
wayn
 
European Exploration And Colonization
European Exploration And ColonizationEuropean Exploration And Colonization
European Exploration And Colonization
wayn
 
. Elsecretoparaserfeliz
. Elsecretoparaserfeliz. Elsecretoparaserfeliz
. Elsecretoparaserfeliz
wayn
 
Jesus Loves You
Jesus Loves YouJesus Loves You
Jesus Loves You
wayn
 
Congestive Heart Failure
Congestive Heart FailureCongestive Heart Failure
Congestive Heart Failure
wayn
 
Koah Patogenezi
Koah PatogeneziKoah Patogenezi
Koah Patogenezi
wayn
 
Paseo Nocturno Night City Tour Of The World
Paseo Nocturno   Night City Tour Of The WorldPaseo Nocturno   Night City Tour Of The World
Paseo Nocturno Night City Tour Of The World
wayn
 
A Better Way
A Better WayA Better Way
A Better Way
wayn
 
Here Comes The Winter
Here Comes The WinterHere Comes The Winter
Here Comes The Winter
wayn
 
Fun On The Net
Fun On The NetFun On The Net
Fun On The Net
wayn
 
Alluring Asia
Alluring AsiaAlluring Asia
Alluring Asia
wayn
 
A Better Way
A Better WayA Better Way
A Better Way
wayn
 
Back To School Presentation
Back To School PresentationBack To School Presentation
Back To School Presentation
wayn
 
Happy new year2008
Happy new year2008Happy new year2008
Happy new year2008
wayn
 
Words.....
Words.....Words.....
Words.....
wayn
 
Referee Image Slide
Referee Image SlideReferee Image Slide
Referee Image Slide
wayn
 
Why I Got Fired
Why I Got Fired Why I Got Fired
Why I Got Fired
wayn
 
New Year 1
New Year 1 New Year 1
New Year 1
wayn
 
Bluetooth Presentation
Bluetooth PresentationBluetooth Presentation
Bluetooth Presentation
wayn
 

Mehr von wayn (20)

Orissa Riots
Orissa RiotsOrissa Riots
Orissa Riots
 
Global Warmin Powerpoint
Global Warmin PowerpointGlobal Warmin Powerpoint
Global Warmin Powerpoint
 
European Exploration And Colonization
European Exploration And ColonizationEuropean Exploration And Colonization
European Exploration And Colonization
 
. Elsecretoparaserfeliz
. Elsecretoparaserfeliz. Elsecretoparaserfeliz
. Elsecretoparaserfeliz
 
Jesus Loves You
Jesus Loves YouJesus Loves You
Jesus Loves You
 
Congestive Heart Failure
Congestive Heart FailureCongestive Heart Failure
Congestive Heart Failure
 
Koah Patogenezi
Koah PatogeneziKoah Patogenezi
Koah Patogenezi
 
Paseo Nocturno Night City Tour Of The World
Paseo Nocturno   Night City Tour Of The WorldPaseo Nocturno   Night City Tour Of The World
Paseo Nocturno Night City Tour Of The World
 
A Better Way
A Better WayA Better Way
A Better Way
 
Here Comes The Winter
Here Comes The WinterHere Comes The Winter
Here Comes The Winter
 
Fun On The Net
Fun On The NetFun On The Net
Fun On The Net
 
Alluring Asia
Alluring AsiaAlluring Asia
Alluring Asia
 
A Better Way
A Better WayA Better Way
A Better Way
 
Back To School Presentation
Back To School PresentationBack To School Presentation
Back To School Presentation
 
Happy new year2008
Happy new year2008Happy new year2008
Happy new year2008
 
Words.....
Words.....Words.....
Words.....
 
Referee Image Slide
Referee Image SlideReferee Image Slide
Referee Image Slide
 
Why I Got Fired
Why I Got Fired Why I Got Fired
Why I Got Fired
 
New Year 1
New Year 1 New Year 1
New Year 1
 
Bluetooth Presentation
Bluetooth PresentationBluetooth Presentation
Bluetooth Presentation
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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...
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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, ...
 
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...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

16 Java Regex

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. A complete example import java.util.regex.*; public class RegexTest { public static void main(String args[]) { String pattern = "[a-z]+"; String text = "Now is the time"; Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(text); while (m.find()) { System.out.print(text.substring ( m.start(), m.end() ) + "*"); } } } Output: ow*is*the*time*
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. The End “ A little learning is a dangerous thing; drink deep, or taste not the Pierian spring: there shallow draughts intoxicate the brain, and drinking largely sobers us again.” --Alexander Pope