Skip to main content
Solved

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

  • December 6, 2017
  • 8 replies
  • 158 views

Best answer by erik_jan

I have created a sample workspace:

find-sondlast.fmw

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

8 replies

fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • December 6, 2017

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.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • December 6, 2017
fmelizard wrote:

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}).

 


  • Author
  • December 6, 2017
fmelizard wrote:

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.


erik_jan
Contributor
Forum|alt.badge.img+18
  • Contributor
  • Best Answer
  • December 6, 2017

I have created a sample workspace:

find-sondlast.fmw


  • Author
  • December 6, 2017
erik_jan wrote:

I have created a sample workspace:

find-sondlast.fmw

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


fmelizard
Safer
Forum|alt.badge.img+18
  • Safer
  • December 6, 2017
erik_jan wrote:

I have created a sample workspace:

find-sondlast.fmw

Thank you @erik_jan

 


takashi
Influencer
  • December 7, 2017
erik_jan wrote:

I have created a sample workspace:

find-sondlast.fmw

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

 

 


paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • December 7, 2017

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])

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