Solved

I would like to extract the second last word in a string using StringSearcher but I'm inexperienced in RegEx. Any suggestions?

  • 6 December 2017
  • 8 replies
  • 31 views

icon

Best answer by erik_jan 6 December 2017, 23:18

View original

8 replies

Userlevel 4
Badge +13

You could also consider using an AttributeSplitter, split based on space character: https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Transformers/Transformers/attributesplitter.htm

Then expose the list element containing the second last word, using the AttributeCreator or AttributeManager. For example expose list element 3, list{2} and rename to a suitable attribute name.

Userlevel 2
Badge +12

You could also consider using an AttributeSplitter, split based on space character: https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Transformers/Transformers/attributesplitter.htm

Then expose the list element containing the second last word, using the AttributeCreator or AttributeManager. For example expose list element 3, list{2} and rename to a suitable attribute name.

Good suggestion @NatalieAtSafe.

 

As an addition: the second last word will be list element -2 (e.g list{-2}).

 

You could also consider using an AttributeSplitter, split based on space character: https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Transformers/Transformers/attributesplitter.htm

Then expose the list element containing the second last word, using the AttributeCreator or AttributeManager. For example expose list element 3, list{2} and rename to a suitable attribute name.

@NatalieAtSafe I like this approach, but I'm having a little trouble getting any output results. I'm guessing I'm not entering the fields correctly, and the list elements are not showing up on the output table. Is there any way to contact you directly and get some assistance? Thanks.

Userlevel 2
Badge +12

I have created a sample workspace:

find-sondlast.fmw

I have created a sample workspace:

find-sondlast.fmw

That's fantastic...worked perfectly. Thanks very much for your help!

Userlevel 4
Badge +13

I have created a sample workspace:

find-sondlast.fmw

Thank you @erik_jan

 

Userlevel 2
Badge +17

I have created a sample workspace:

find-sondlast.fmw

Alternatively, the ListIndexer can be used here. e.g.

 

 

Badge +4

use a onliner in pythoncaller:

in input function write:

feature.setAttribute('Your_new_attribute',feature.getAttribute('attribute_with_words_i_want_the_second_last').split(' ')[-2])

Reply