I have the following string in an attribute: "Jan 1 1960; Jan 1 1900; Jan 1 1960; 01/05/1890; Jan 1 1960; Jan 1 1960; Jan 1 1960; Jan 1 1960; Jan 1 1960; Jan 1 1960; " I need to extract the earliest year from the attribute, since this is input from a reader the attribute will have different values, but the year will always be in a 4 digit format. I want to use a regular expression to extract the earliest year, in this case it would be 1890. Is this possible?
Page 1 / 1
Here's one way:
- StringSearcher with a regex like "\\d{4}" to extract all occurrences of 4 consecutive digits. Specify a list name for all the "All matches list name"
- ListSorter in ascending numerical order on the match list
- ListIndexer on item 0 to extract the lowest number
Example:
Here's one way:
- StringSearcher with a regex like "\\d{4}" to extract all occurrences of 4 consecutive digits. Specify a list name for all the "All matches list name"
- ListSorter in ascending numerical order on the match list
- ListIndexer on item 0 to extract the lowest number
Example:
Thanks for your answer David. I'm Using FME 2016, the ListSorter transformer doesn't have the defined list in StringSearcher available.
Here's one way:
- StringSearcher with a regex like "\\d{4}" to extract all occurrences of 4 consecutive digits. Specify a list name for all the "All matches list name"
- ListSorter in ascending numerical order on the match list
- ListIndexer on item 0 to extract the lowest number
Example:
In FME 2016 I've used the Subexpression Matches List Name which makes the list available to the ListSorter
Just for fun. Sometimes FME can solve a puzzle with a collaborative work of string/math operations and geometric operations.
Set OGC Well Known Text to the Geometry Encoding parameter, and set this expression to the Geometry Source parameter in the GeometryReplacer
LINESTRING(@Trim(@ReplaceRegEx(;@Value(text),";.+?(?=\d{4})",",0 "),",; "))