Question

string replacer with numbers

  • 4 November 2014
  • 4 replies
  • 2 views

Badge
I have a value of FAIRFIELD WORKS, FAIRFIELD, AL 35064 that I need to change to FAIRA.  However I am getting FAIRA 35064.  I have my string replacer set as follows

 

 

Text to Find: FAIRFIELD WORKS, FAIRFIELD, AL 35064

 

Replacement Text: FAIRA

 

Use regular Expressions: No

 

Case Sensitive: No

 

 

How can I get rid of 35064.

 

 

thanks

 

Dan

4 replies

Badge +3
regexp = (.*)\\s\\d*

 

 

Use regular Expressions: YES

 

 

expose or use creator or renamer on "matched_parts{0}"
Badge
does this work with conditional parameters?  I have other values in the field such as Warren, OH that do not need changed or do I need to add a Tester

 

 
Userlevel 2
Badge +17
Hi Dan,

 

 

Please check the input attribute value.

 

If the attribute stores "FAIRFIELD WORKS, FAIRFIELD, AL 35064 35064" (the number is duplicated), the resulting string will be "FAIRA 35064" naturally. 

 

 

Takashi
Badge +3
Lol Takashi,

 

 

i changed the regexp to ([a-zA-Z,\\s]*)\\s\\d*

 

(FME regexp flavor does'nt want to do

 

 (.*)\\s\\d* or ([\\w,\\s]*)\\s\\d* Though in other aplications it works like above)

 

 

 

 

If u have specific objects that need changed u need to test for those yes.

 

In conditional you need to use different aproach, u can  use tcl string and listfunctions.

 

Though this is somewhat more complex

 

 

You could do like conditional:

 

test condition: 

 

@Value(adres) like %FAIRFIELD%

 

outputfield:@Evaluate([string replace {@Value(tst)} @Evaluate([lindex {@Evaluate(@Evaluate([regexp -indices {(.*)\\s\\d*} {@Value(tst)} M SM])==1?"$SM":"none")} 0]) @Evaluate([lindex {@Evaluate(@Evaluate([regexp -indices {([a-zA-Z,\\s]*)\\s\\d*} {@Value(tst)} M SM])==1?"$SM":"none")} 1]) {@Value(Replacement)}])

 

 

...;)

 

i set a attribute @Value(Replacement) to "FAIRA "

 

 

this replaces "FAIRFIELD WORKS, FAIRFIELD, AL 35064" to "FAIRA 35064"

 

 

You might not want to go there and just use transformers: tester, stringsearchers and stringreplacers.

 

 

Reply