Skip to main content
Question

Using stringreplacer with conditional values and regular expressions


fmenco
Contributor
Forum|alt.badge.img+5

Hi, I have an address dataset with the usual errors like abbreviated streetnames (str instead of street, ln instead of lanes, bd instead of boulevard) etc.

I want these written out, and by using regular expressions with individual stringreplacers I can get this to work.

However, I want just one stringreplacer to do the job. When I try this, I get empty values for the streetname attribute, so I think my parameters must not be filled in correctly, or I messed up the syntax on the regular expressions maybe.

Where do I set my conditions? In the "Text to replace" field, or in the "replacement text" field?

Right now, one of my conditions is:

test condition:

IF: @Value(street) CONTAINS_REGEX str$

Output Value:

street

I've tried numerous ways, using reg expresions as output value, or using string functions, none worked.

Can I get a clear example from someone?

5 replies

david_r
Evangelist
  • March 7, 2018

I just tested with a feature containing an attribute "street" with the value "Bleaker str" and the following Tester:

Seems to work as expected in FME 2017.1.2.

Could you perhaps post a minimal working example workspace that demonstrates the issue?


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • March 7, 2018

@fmenco

in the stringreplacer "use regexp" = yes

string to search

(.)str$

replacement

\\1 street

explanation:

the (.) captures anything in front of str

\\1 places the first capture group (in this case there is only one)


fmenco
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • March 7, 2018
gio wrote:

@fmenco

in the stringreplacer "use regexp" = yes

string to search

(.)str$

replacement

\\1 street

explanation:

the (.) captures anything in front of str

\\1 places the first capture group (in this case there is only one)

I tried this, and it didn't work. I still get empty values for my street name attribute. I tried it with conditional values. I tried changing str, bd, ln etc through different conditional values and that just seems to erase the values.

 

A string replacer for each scenario does work, but then I end up with about 9 stringreplacers after each other in one work bench.

 

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 8, 2018

Hi @fmenco, if the abbreviated words could appear only at the end of an address string, this would be a possible way.

Regular Expression:

(?<=\s)(str|ln|bd)$

StringReplacer Parameters:

0684Q00000ArJtFQAV.png

However, it's not good at maintainability and extensibility. If you are familiar with a scripting language such as Python, Tcl, or JavaScript, I think it would be better to consider writing a script in this case.


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • March 8, 2018
gio wrote:

@fmenco

in the stringreplacer "use regexp" = yes

string to search

(.)str$

replacement

\\1 street

explanation:

the (.) captures anything in front of str

\\1 places the first capture group (in this case there is only one)

 

i use fme 2016 and it does work.

 

 

 

and (.)(?:str|bd|ln|blvd) etc.

 

 

(?:) is non capturing.

 


Reply


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