• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Introduction to Regular Expressions

on

  • 3,804 views

Introduces regular expressions and their power. Example code at http://resume.jesse-anderson.com/regex.zip.

Introduces regular expressions and their power. Example code at http://resume.jesse-anderson.com/regex.zip.

Statistics

Views

Total Views
3,804
Views on SlideShare
3,773
Embed Views
31

Actions

Likes
5
Downloads
0
Comments
0

10 Embeds 31

http://apps.mindtalk.com 9
http://www.linkedin.com 6
http://www.mindtalk.com 5
https://twitter.com 4
http://localhost 2
https://www.linkedin.com 1
https://twimg0-a.akamaihd.net 1
http://a0.twimg.com 1
http://us-w1.rockmelt.com 1
http://orhowilearnedtolovetheperl.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to Regular Expressions Introduction to Regular Expressions Presentation Transcript

    • Regular Expressions
      • Jesse Anderson
    • What Are They?
      • Language to parse text
      • Apply logic and constraints
      • Concise (but not readable)
      • Consistent (mostly)
      • Widely supported in programming languages
    • Hello Regex Source Text Regular Expression Yield “ hello world” “ hello” { “hello” } “ hello world hello world” “ hello” { “hello”, “hello” } “ hello world hello world” “ world” { “world”, “world” } “ hello world hello world” “ hello world” { “hello world”, “hello world” }
    • Java Regex Code Pattern pattern = Pattern.compile( "hello" ); Matcher matcher = pattern.matcher( " hello world " ); // Find all matches while (matcher.find()) { // Get the matching string String match = matcher.group(); // match = “hello” }
    • C# Regex Code foreach (Match match in Regex.Matches( " hello world " , " hello " , RegexOptions.IgnoreCase)) { // Get the matching string String match = match.Value; // match = “hello” }
    • Python Regex Code regex = re.compile( " hello " ); results = regex.search( " hello world " ); // results = " hello "
    • Perl Regex Code $value = " hello world "; $value =~ m/hello/; $result = $1; // result = " hello "
    • The (Ugly) Alternative String needle = "hello"; String haystack = "hello world hello world"; int index = 0; while ((index = haystack.indexOf( needle, index )) != -1) { String match = haystack.substring( index, index + needle.length() ); index++; }
    • Regex Metacharacters
      • * - Match zero or more times
      • ? - Match zero or 1 time
      • + - Match one or more times
      • ^ - Match the start of a string
      • $ - Match the end of a string
    • Character Classes POSIX Shorthand Longhand Description [:word:] w [A-Za-z0-9_] Alphanumeric Chars. W [^A-Za-z0-9_] Non-alphanumeric Chars. [:alpha:] [A-Za-z] Alphabetic Chars. [:blank:] [ ] Space and tab [:digit:] d [0-9] Numeric Characters D [^0-9] Non-numeric Chars. [:space:] s [ vf] Whitespace Characters
    • Groups Source Text Regular Expression Yield “ hello world” “ ([a-z]+)s+([a-z]+) { “hello world”, “hello”, “world” } “ hello world12345” “ ([a-z]+)s+([a-z]+) { “hello world”, “hello”, “world” } “ hello world12345” “ ([a-z]+)s+([a-z]+)(d+) { “hello world12345”, “hello”, “world”, “12345” }
    • Example
      • Example that parses, cleans up, and normalizes input
    • Recommended Reading
      • Mastering Regular Expressions by Jeffry Friedl
      • Regular Expressions Cheat Sheet http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/
      • Regex Evaluator http://www.cuneytyilmaz.com/prog/jrx/