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
  • 191 views

Best answer by erik_jan

I have created a sample workspace:

find-sondlast.fmw

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

8 replies

fmelizard
Safer
Forum|alt.badge.img+20
  • Safer
  • 3719 replies
  • 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+22
  • Contributor
  • 2179 replies
  • 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.

Good suggestion @NatalieAtSafe.

 

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

 


  • Author
  • 2 replies
  • 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.

@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+22
  • Contributor
  • 2179 replies
  • Best Answer
  • December 6, 2017

I have created a sample workspace:

find-sondlast.fmw


  • Author
  • 2 replies
  • December 6, 2017

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+20
  • Safer
  • 3719 replies
  • December 6, 2017

I have created a sample workspace:

find-sondlast.fmw

Thank you @erik_jan

 


takashi
Celebrity
  • 7843 replies
  • December 7, 2017

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
  • 130 replies
  • 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])