Regular Expression

From Fmepedia


A (advanced) regular expression (ARE for short) is a special text string for describing a search pattern, much like a wildcard, but a lot more powerful. Several FME transformers that operate on text strings can use regular expressions. Examples of these are the Grepper, ListSearcher, and StringReplacer.

ARE's work with special characters which indicate how the expression is to be applied on the subject text string.

A brief summary of the special characters and their meanings is:

|   separates "branches" (or choices)
*   a sequence of 0 or more matches of what precedes it
+   a sequence of 1 or more matches of what precedes it
?   a sequence of 0 or 1 matches of what precedes it
.   matches any single character
^   matches the start of the value
$   matches the end of the value
[ ] enclose a set of character choices
( ) enclose a "subexpression" -- whatever matches each subexpression is placed into the _matched_parts{} 
    list attribute
a   any character can be listed to be matched

Examples:

^A   matches any value starting with an A
^[0-9]   matches any value starting with a digit
^[0-9]+$   matches any value consisting exclusively of digits
^(beef|chicken)$   matches values of either “beef� or “chicken�
^(T|t)[A-Za-z][A-Za-z]$  matches all 3-letter words starting with a T or t.

More information and samples on the use of regular expressions can be found at http://www.regularexpressions.info/

User Comments Add a new comment