Regular Expressions: Character Sequences for String Matching

Regular Expressions: Character Sequences for String Matching
Slide Note
Embed
Share

In this learning material, Dr. Lisa Frye introduces regular expressions and their usage for string matching. The content covers essential concepts such as character sequences, special characters, quantifiers, POSIX character classes, alternations, groups, and practical examples. Students explore how to match specific patterns, manipulate text data effectively, and enhance their coding skills. Gain insights into using regular expressions efficiently for a variety of tasks in programming and text processing.

  • Regular Expressions
  • String Matching
  • Character Sequences
  • Coding Skills
  • POSIX Classes

Uploaded on Apr 22, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. John Carelli,Instructor Kutztown University carelli@kutztown.edu

  2. Regular Expressions Character sequences used for string matching Matches longest pattern CSC352: John Carelli Source: Dr. Lisa Frye

  3. .Any single character [] Any single character in [] -Range of characters ^ If first character any character NOT in [] * Matches zero or more occurrences ^ At beginning of reg exp, matches beginning of line $ At end of reg exp, matches end of line \ Quote a special character (escape character) CSC352: John Carelli Source: Dr. Lisa Frye

  4. + Matchesone or more occurrences ? Matches zero or one occurrences | Boolean OR CSC352: John Carelli Source: Dr. Lisa Frye

  5. \d \w \s CSC352: John Carelli Source: Dr. Lisa Frye

  6. POSIX [:alnum:] [:alpha:] [:ascii:] [:blank:] [:digit:] [:lower:] [:space:] Description Alphanumeric characters Alphabetic characters ASCII characters Space and tab Digits Lowercase letters All whitespace characters,including line breaks [:upper:] [:word:] Uppercase letters Word characters (letters,numbers and underscores) CSC352: John Carelli Source: Dr. Lisa Frye

  7. | Alternation ( or ) ex: cat|dog Repetition more granularity than * or + Includes two optional numbers in the braces Minimum Maximum ex: [1-9][0-9]{2,4} matches numbers between 100 and 99999 { } Group operator ( ) CSC352: John Carelli Source: Dr. Lisa Frye

  8. Well you know it s your bedtime, So turn off the light, Say all your prayers and then, Oh you sleepy young heads dream of wonderful things, Beautiful mermaids will swim through the sea, And you will be swimming there too. CSC352: John Carelli Source: Dr. Lisa Frye

  9. Match any line that contains at least one character Match any line that contains at least two characters Match any line that begins with a # Match all blank lines Match any line that contains a lowercase a , b ,or c Match any line that begins with an a , b ,or c CSC352: John Carelli Source: Dr. Lisa Frye

  10. Match any 3-letter word ending inat Match any consonant letter Find any occurrence of the word chapter Write a regular expression that matches the following strings and only the following strings: May dd,yy may dd,yy Write a regular expression that will find a line containing a floating-point number greater than 100 MatchTom orThomas CSC352: John Carelli Source: Dr. Lisa Frye

  11. Stream EDitor utility sed [-n] program [filelist] sed [-n] -f program-file [filelist] sed "s/UNIX/Unix/g" thesis > thesis.new CSC352: John Carelli Source: Dr. Lisa Frye

  12. http://www.genuinecoder.com/2013/05/unix-shell-programming-grep-sed-awk.htmlhttp://www.genuinecoder.com/2013/05/unix-shell-programming-grep-sed-awk.html CSC352: John Carelli Source: Dr. Lisa Frye

  13. A C D I N n p q r <file> s w <file> Append Change Delete Insert Append next line to current line (remove NEWLINE) Next - writes out current line and reads next line Print Quit Read file Substitute Write to file CSC352: John Carelli Source: Dr. Lisa Frye

  14. List only files in your directory (no directories) Delete leading blanks at beginning of every line of a file Replace all strings of blanks with one blank Delete empty lines or lines with only spaces in it CSC352: John Carelli Source: Dr. Lisa Frye

  15. Delete all lines from the beginning of the file up to,and including the first blank line Change of sequences of zeroes into one zero Change all occurrences of Adhesions to Coatings in lines that contain Digital CSC352: John Carelli Source: Dr. Lisa Frye

More Related Content