Greedy Reluctant Possessive Example: ".*a" Apply match as many times as possible Matches string "aaaa" Apply as few times as possible Matches string "aaaa" Does not match those that greedy or reluctanct may match. For performance reasons only, this is basically a greedy search without a backup & alternative. Notation a* means 0 or more a's (keep matching a's as much as possible) Example: regular expression = ".*a" Target string: aaaab Note: to search for the "." or "*" characters, use a backslash before the character. Example: to search for a period, enter \. Deterministic Finite State Automaton (DFA) Simple machine with N states Validity checking program String re = args[0]; String input = args[1]; StdOut.println(input.matches(re)); public static void main(String[] args) { } public class Validate { } Validate asks whether the pattern could compose the string Harvester asks whether the pattern exists anywhere in the string String Searching Methods public class String boolean matches(String re) String replaceAll(String re, String str) int indexOf(String r, int from) String[] split(String re) does this string match the given re replaces all instances of the re with a new string return the index of the first occurrence of the string r after the index from split the string around matches of the given re Example uses: % java Validate "C.{2,4}C?[LIVMFYWC].{8}H.{3,5}H" CAASCGGPYACGGAAGYHAGAH true %java Validate "[$_A-Za-z][$_A-za-z0-9]*" ident123 true %java Validate "[a-z]+@([a-z]+\.)+(edu|com)" wayne@cs.princeton.edu true In Java, you have to include two backslashes "\\" in regular expression referral, due to the way the compiler works. see also: Finite State Automaton (FSA) Non-Deterministic Finite State Automaton (NFA) 4.9.10 Regular Expressions Continued Friday, April 09, 2010 3:02 PM
STUDYBLUE makes things that make you better at school.
Things like
online flashcards with photos and audio.
Things like personalized quizzes and friendly reminders about when (and what) to study next.
Think of it as a digital backpack™: access to all of your study materials online and on your phone.
STUDYBLUE exists to make studying efficient and effective for every student, for free.
Join us.
“I have used this website for three exams, and I see a huge difference in my test results.”
Naj