Skip to main content
Question

How to keep Selected Strings in Multi-Line Field and Replace Others with Spaces?


gogopotter90
Contributor
Forum|alt.badge.img+13

Hello,

 

I have a field consisting of two lines:

Line 1: (empty space) String1 (empty space) String2 (empty space) String3 (empty space)

Line 2 : (empty space) String5 (empty space) String6 (empty space) String7 (empty space) String8

Both lines exist within the same field.

My objective:
If I choose to keep, for example, **String1** from Line 1 and **String5** from Line 2, then all other strings in their respective lines should be replaced with empty spaces.

Alternatively, if I choose to keep **String3** from Line 1 and **String7** from Line 2, the rest of the strings in each line should become empty spaces.

In short, I want the ability to retain specific strings from each line while replacing all others with empty spaces.

example :
 

Thanks in advance 

7 replies

alexbiz
Supporter
Forum|alt.badge.img+10
  • Supporter
  • May 25, 2025

Hey !

You’ll need to disassemble, filter, and then reassemble your field value.

You can do that using a combination of AttributeSplitter and ListExploder. First, split your field on new line/carriage return to separate the lines, then split each line on space characters to get individual strings.

Once you have the values split into distinct features, you can filter them based on their index, kind of like picking a specific cell from a 2D table (for example, row 0 column 2).

After filtering, you can rebuild the field by concatenating the values back together. You can use ListBuilder + ListConcatenator for that, or even Aggregator if you’re comfortable with it (personally, I don’t love using it for attribute manipulation, but it works).

Hope that helps!


gogopotter90
Contributor
Forum|alt.badge.img+13
  • Author
  • Contributor
  • May 25, 2025

@alexbiz 

Thanks for reply .

I understood  what you mean, but is there a way to do it without splitting them ?


Is there a direct solution , maybe using a string searcher or using RegularExprewsionReplacer   to keep only the parts I want and change the rest in the same  line to empty space ?


alexbiz
Supporter
Forum|alt.badge.img+10
  • Supporter
  • May 25, 2025

Sure, you could use an StringReplacer with regular expression if you’re good at that. But that’s a non-FME solution then. And in my opinion, if you’re not able to write it on your own, It will be hard to maintain over time (for you or any person going after you on your workspace if that happen). So a “direct” solution is not a better solution.
I’m not personally an expert at regex, but AI exist for that kind of thing if you need that.


hkingsbury
Celebrity
Forum|alt.badge.img+54
  • Celebrity
  • May 25, 2025
gogopotter90 wrote:

@alexbiz 

Thanks for reply .

I understood  what you mean, but is there a way to do it without splitting them ?


Is there a direct solution , maybe using a string searcher or using RegularExprewsionReplacer   to keep only the parts I want and change the rest in the same  line to empty space ?

 

You could do it in Regex, with this string:
 

\b(?!hello\b)\w+\b

I’ll happily use regex where it is simpler than an FME native approach, in this case, you’re making use of a negative look ahead with word boundaries which is on the more complex end of regex I’d tend to use in FME.

Alexs’ approach would be pretty simple in FME and relatively self documenting. The regex approach would need some robust documentation to help someone understand it.


gogopotter90
Contributor
Forum|alt.badge.img+13
  • Author
  • Contributor
  • May 28, 2025

@hkingsbury 

Thanks for your suggestion, but if the word is not always fixed.
I think you provided "hello" word as a fixed string, but if the string is unknown, as example

how can we use regex to keep the fourth word after spaces and change other strings to empty space  ?

 


takashi
Influencer
  • May 29, 2025

Hi ​@gogopotter90 ,

If the requirement is to extract the Nth word in the space-separated multiple words, I don't think regular expression is a suitable solution. I would recommend you to use AttributeSplitter to split and populate them into a list attribute as ​@alexbiz mentioned, then extract the Nth word from the list with ListIndexer.


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • June 2, 2025

Can the GetWord string function help you here?

GetWord(string,index)

Returns the indexth word in string. [...] Words in string must be delineated by blank spaces (space, tab, return carriage, and others).

Note that GetWord starts at index 0, so String1 has index 0, String5 has index 4.

 


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