Monday, 29 October 2007

Ch3, lesson 1 - Forming Regular Expressions.

  • Text processing - pattern matching, (sub)string extraction, (sub)string replacement.

Pattern Matching

  • namespace - System.Text.RegularExpressions.
  • statc mthd - System.Text.RegularExpressions.Regex.IsMatch(,);
  • ^,$ - begin, end.
  • \b - word boundary.
  • \B - match NOT on a \b boundary.
  • @ - backslashes are treated literally.
  • * >=0
  • + >=1
  • {n} - repeat previous char n times.
  • {n,m} - repeat prev char bet n & m times.
  • {n,} - repeat previous char min n times.
  • ? - prev. char optional.
  • . - single char.
  • [] - character class/range - e.g. [0-9] = \d
  • \d - numeric digit, \D - non-numeric char - [^0-9]
  • \s - white-space char, \S - non-white space char
  • \w - word char = [a-zA-Z0-9_], \W - [^a-zA-Z0-9_]
  • () - to match group of chars
  • (?pattern) - name a group - to refer to matched data later.
  • backreferencing - to find repeating groups of characters.
  • (?\w)\k - finds doubled word characters.
  • \1 - 1st backreference in a reg expr, \2 - 2nd backref in regex,...
  • extract matched data - access elts of Match>Groups array.
  • Replace substrings using reg expr...

No comments: