Skip to main content

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?

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.

 

 


Thanks for your answer David. I'm Using FME 2016, the ListSorter transformer doesn't have the defined list in StringSearcher available.

 

 

It should be there if you expand the Advanced part

 

 


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

 

 


In FME 2016 I've used the Subexpression Matches List Name which makes the list available to the ListSorter

 

 

FME 2016 and 2017 are identical on this point, you need to specify the "All matches list name", not the "Subexpression matches list name" (there are no sub-expressions in this regex).

Just for fun. Sometimes FME can solve a puzzle with a collaborative work of string/math operations and geometric operations.

0684Q00000ArL2gQAF.png

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 "),",; "))

Reply