Question

How Can I remove everything after "-" in FME using string replacer?

  • 14 February 2018
  • 8 replies
  • 312 views

Badge

Hello.

 

 

I would like to remove (replace with no text) everything what is after dash also with the dash.

 

What I have: test - fme

What I want: test

Cheers,

 

Oliwer


8 replies

Badge +1

Hi,

If you use StringReplacer with these parameters, that should do the trick...

Badge

Thank you very much. That works. Can you please explain me that Expression so I can understand what happened there exactly?

Badge +8

Hi,

If you use StringReplacer with these parameters, that should do the trick...

 

Do you have a website in mind that can generate automatically that kind of expression?
Badge +1

Thank you very much. That works. Can you please explain me that Expression so I can understand what happened there exactly?

Certainly. So regex is a way to search through your string based on some rules. In this case rules are as follows:

 

\\- means "find - character"

 

.* means "find every character"

 

$ means "until the end of string"

 

 

Together they are: find every character from - character (including) until the end of string.

 

 

If you use FME 2016+ there's a really neat quick reference and testing option inside StringReplacer. With it you can create many of your regular expressions.

 

 

Cheers.

 

Badge +1

 

Do you have a website in mind that can generate automatically that kind of expression?
Unfortunatelly, I'm not aware of that. There are some that give you explanation based on your expression, though.

 

 

Just to follow up on this. This is how you would remove everything located before the dash.

^.*\\-

 

It took me a few minutes to figure it out so I thought I would share.

Userlevel 4
Badge +25

Since this question has just popped back to the top of the list, I thought I'd mention the hub transformer called LastSectionOfStringRemover, which would probably handle what the original question called for.

Badge

Since this question has just popped back to the top of the list, I thought I'd mention the hub transformer called LastSectionOfStringRemover, which would probably handle what the original question called for.

This Transformer is a Godsend... have been scratching the head until i seen your comment @mark2atsafe​ ! I've used it to extract a URL from a Name field extracted from an ESRI Story map. Cheers.

Reply