regular expressions are accessible in most programing languages...used for pattern matching. DFA and NFA: Deterministic Finite Automation and Nondeterministic Finite Automation an art project needs to come out of regular expressions perl regex operates almost identical to sed good examples: Example 1-1. Simple match # Match Spider-Man, Spiderman, SPIDER-MAN, etc. my $dailybugle = "Spider-Man Menaces City!"; if ($dailybugle =~ m/spider[- ]?man/i) { do_something( ); } Example 1-2. Match, capture group, and qr # Match dates formatted like MM/DD/YYYY, MM-DD-YY,... my $date = "12/30/1969"; my $regex = qr!(\d\d)[-/](\d\d)[-/](\d\d(?:\d\d)?)!; if ($date =~ m/$regex/) { print "Day= ", $1, "Month=", $2, "Year= ", $3; } Example 1-3. Simple substitution # Convert
to
for XHTML compliance my $text = "Hello World!
"; $text =~ s#
#
#ig; Example 1-4. Harder substitution # urlify - turn URL's into HTML links $text = "Check the website, http://www.oreilly.com/catalog/repr."; $text =~ s{ \b # start at word boundary ( # capture to $1 (https?|telnet|gopher|file|wais|ftp) : # resource and colon [\w/#~:.?+=&%@!\-] +? # one or more valid # characters # but take as little as # possible ) (?= # lookahead [.:?\-] * # for possible punctuation (?: [^\w/#~:.?+=&%@!\-] # invalid character | $ ) # or end of string ) }{$1}igox; JAVA: "\\b # start at word\n" + " # boundary\n" + "( # capture to $1\n" + "(https?|telnet|gopher|file|wais|ftp) : \n" + " # resource and colon\n" + "[\\w/\\#~:.?+=&%@!\\-] +? # one or more valid\n" + " # characters\n" + " # but take as little\n" + " # as possible\n" + ")\n" + "(?= # lookahead\n" + "[.:?\\-] * # for possible punc\n" + "(?: [^\\w/\\#~:.?+=&%@!\\-] # invalid character\n" + "| $ ) # or end of string\n" + ")"; almost all regex in different languages use the same nomenclature javascript //Convert
to
for XHTML compliance String text = "Hello world.
"; var pattern = /
/ig; test.replace(pattern, "
"); yesssss: sed: $ echo 12/30/1969' | sed 's!\([0-9][0-9]\)/\([0-9][0-9]\)/\([0-9]\{2,4\}\)!\2.\1.\3!g'