the college of saint rose cis 433 programming languages david goldschmidt ph d n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Regular expressions {week 06} PowerPoint Presentation
Download Presentation
Regular expressions {week 06}

Loading in 2 Seconds...

play fullscreen
1 / 7

Regular expressions {week 06} - PowerPoint PPT Presentation


  • 98 Views
  • Uploaded on

The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. Regular expressions {week 06}. from Concepts of Programming Languages , 9th edition by Robert W. Sebesta, Addison-Wesley, 2010, ISBN 0-13-607347-6. Regular expressions ( i ).

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Regular expressions {week 06}' - ivor-cochran


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
the college of saint rose cis 433 programming languages david goldschmidt ph d
The College of Saint Rose

CIS 433 – Programming Languages

David Goldschmidt, Ph.D.

Regular expressions{week 06}

from Concepts of Programming Languages, 9th edition

by Robert W. Sebesta, Addison-Wesley, 2010, ISBN 0-13-607347-6

regular expressions i
Regular expressions (i)
  • A regular expression is an expression ina “mini language” designed specificallyfor textual pattern matching
    • Support for regular expressions are availablein many languages, including Java, JavaScript,C, C++, PHP, etc.
regular expressions ii
Regular expressions (ii)
  • A pattern contains numerous character groupings and is specified as a string
  • Patterns to match a phone number include:
    • [0-9][0-9][0-9]−[0-9][0-9][0-9]−[0-9][0-9][0-9][0-9]
    • [0-9]{3}−[0-9]{3}−[0-9]{4}
    • \d\d\d−\d\d\d−\d\d\d\d
    • \d{3}−\d{3}−\d{4}
    • (\d\d\d) \d\d\d−\d\d\d\d
regular expressions in java i
Regular expressions in Java (i)
  • The String class in Java provides a pattern matching method called matches():
    • Unlike other languages, Java requires the pattern to match the entire string

String s = "Pattern matching in Java!";

String p = "\\w+\\s\\w+\\s\\w{2}\\s\\w+!";

if ( s.matches( p ) )

{

System.out.println( "MATCH!" );

}

regular expressions in java ii
Regular expressions in Java (ii)
  • Additional pattern-matching methods:
    • Use the replaceFirst() and replaceAll() methods to replace a pattern with a string:

String s = "<title>Cool Web Site</title>";

String p = "</?\w+>";

String result = s.replaceAll( p, "" );