Skip to main content
Solved

Regular Expression to extract the earliest year from Attribute


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?

Best answer by david_r

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:

View original
Did this help you find an answer to your question?

6 replies

david_r
Celebrity
  • Best Answer
  • November 9, 2017

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:


  • Author
  • November 9, 2017
david_r wrote:

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.

 

 


ebygomm
Influencer
Forum|alt.badge.img+39
  • Influencer
  • November 9, 2017
saqibamin wrote:
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

 

 


  • Author
  • November 9, 2017
david_r wrote:

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

 

 


david_r
Celebrity
  • November 9, 2017
saqibamin wrote:
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).

takashi
Evangelist
  • November 9, 2017

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

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings