previous | start | next

Regular Expression Multipliers

How do you write a pattern that matches 1, 2, 3, or more whitespace characters?

Answer: Use a multiplier:

A * following a regular expression means 0 or more occurrences.

A + following a regular expression means 1 or more occurrences.

So,

      "\\s*,\\s*"    matches 0 or more whitespace characters followed by
                     a comma, followed by 0 or more whitespace
                     characters.
      "[ \r\t\n]+"   (What does this match?)
      "[\\s,.!?]+"   (What does this match?)
   


previous | start | next