# Regular Expression Examples

The following table shows some examples of regular expressions, with samples of strings that they would match and not match.

Remember that '\' is an escape character - it is used to take away the special meaning of the character that follows it. Look at "od*" and "od\*" in the table below to make sure you understand this.

See Regular Expression Syntax for an explanation of the other special characters.
In the examples, below, we assume that the input record has fields with contents:
Field1 = "Acme Corp"
Field2 = "Jones"
Field3 = "food"

Pattern | Description | Matches | Doesn't Match
"stuff" | The string "stuff" | "stuff" | anything else
"^stuff" | "stuff" when it occurs at the start of a line | "stuff", "stuff this" | "dont stuff this"
"stuff$" | "stuff" when it occurs at the end of a line | "stuff", "no more stuff" | "dont stuff this"
"o.d" | "o", any character, "d" | "old", "odd", "oxd" | "olld", "od"
"o[ld]d" | "o", one of "l" or "d, then "d" | "old", "odd" | "oxd"
"o[^l]d" | "o", any character except "l", then "d" | "odd", "ord" | "old"
"od." | "od" then any single character | "odd", "odx", "oda" | "od", "old"
"od+" | "o" then one or more occurrences of "d" | "od", "odd", "oddd" | "o", "old"
"od?" | "o" then zero or one occurrence of "d" | "o", "od" | "odd"
"od*" | "o" then zero or more occurrences of "d" | "o", "od", "odd" | "old"
"od\*" | "od" and the character "*" | "od*" | "od", "odd"
"[A-Z][a-z]*" | Any word starting with an uppercase letter | "Fred", "Word", "A", "The" | "fred", "word", "a", "the"
"[0-9]+" | Any sequence of one or more digits | "1", "12", "456", "012" | "a1", "1.0"
"[1-9]+[0-9]*" | Any sequence of one or more digits, not starting with "0" | "1", "12", "120" | "012", "1.0"
"[+\-]?[0-9]*[\.]?[0-9]*" | Any number with optional "+" or "-" sign at the front, and optional decimal point | "1", "1.0", "-1.0", "0.5", "0", "-012.345" | "1+", "1.2.3"
"#Field1" | The contents of field number 1 in the input record | "Acme Corp" | anything else
"#Field3 loves #Field2" | Contents of field 3, the word " loves ", then the content of field 2 | "Jones loves food" | anything else

One of the best ways to develop and quickly test your patterns is using the Filter or Transform stages of the Profile Editor. You can develop a regular expression to use as a filter or to change an input record, then click the Apply button and see the results in the Preview Pane). If the results are not what you require, change the expression and click the Update Preview button again; the results will be updated immediately.

Note that if a pattern can match the string in more than one way, the longest match will prevail. For example, suppose we have the test:

".*,"

which means "any sequence of characters terminating in a comma", and we have an input field with the value:

"one, two, three, four"

Possible matches would be:

"one,"
"one, two,"
"one, two, three,"

In cases like this, the longest possible match will be used; thus the match would be "one, two, three,".