Regular Expression Examples
A simple example for a regular expression is a (literal) string. For example, the Hello World regex will match the “Hello World” string. A “.” (dot) is another example for a regular expression. A dot matches any single character, for example: “a”, “z”, or “1”.
The following table lists example regular expressions and describes the pattern they would match.
Regular Expression |
Matches |
---|---|
this is text |
Matches exactly “this is text”. |
this\s+is\s+text |
Matches the word “this” followed by one or more whitespace characters followed by the word “is” followed by one or more whitespace characters followed by the word “text”. |
^\d+(\.\d+)? |
^ defines that the patter must start at beginning of a new line. \d+ matches one or several digits. The ? makes the statement in brackets optional. \. matches “.”, parentheses are used for grouping. Matches for example “5”, “1.5” and “2.21”. |