Best answer by erik_jan
View originalI would like to extract the second last word in a string using StringSearcher but I'm inexperienced in RegEx. Any suggestions?
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.
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.
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.
I have created a sample workspace:
I have created a sample workspace:
That's fantastic...worked perfectly. Thanks very much for your help!
I have created a sample workspace:
I have created a sample workspace:
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
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.