SEARCH W7R

Wednesday, January 16, 2013

Regex Tutorial 2: Repeat This, Repeat That

w7r.blogspot.com

Let's Avoid Being Redundant!

Regular Expressions can save you a lot of time, by describing complicated patterns that would be ridiculous to search documents for with a standard Search and Replace.

Repeat Operators

Symbol Quantity Example
+ One or more
Regex Captures Ignores
"w+" "w", "wwwww", "wkd", "switch" "123", "mango", "smiley_faces", ""
* Zero or more
RegexCapturesIgnores
"a*" "aab", "ab", "b", "LotsOfStuff", "" NO CASES
? one or zero
RegexCapturesIgnores
"2?" "2", "a", "2a", "a2" "22", "0122", "a22b"

Practice Makes Perfect

Try and create the simplest regular expression to identify each text case below! Feel free to comment your answers. FYI: We are taking baby steps so if this is too easy (which it very well may be!) then feel free to skip this exercise.

  1. aaabbbbccccc
  2. knee
  3. cabbage
  4. 22nd street
Answers to these questions will be in Regex Tutorial #3.

No comments: