Skip to main content

In my workbench I have a column full of strings where I'd like certain sequences of characters to be capitalized. I could do this by adding a StringReplacer for each sequence, but I have a lot of sequences and I'd rather not do that if I can solve the problem with a general solution. What I'd like to do is just use some StringReplacer like

Attributes: RAILWAY_NAME

Text to Find: Cpr|Cnr

Replacement Text: @UpperCase(\\0)

Use Regular Expressions: Yes

Case Sensitive: Yes

Where whatever it finds would be replaced with the upper case version. But when I try this on the string "Cnr Railway" nothing gets replaced. If I try it with the replacement text \\0+1 I get "Cnr+1 Railway", so I know the regex is matching correctly. If I try it with the replacement text @StringLength(\\0) I get "2 Railway", so it looks like functions take "\\0" as a literal string. But if that were the case why does @UpperCase(\\0) return "Cnr Railway"?

So my quesiton is:

1. Can I use FME String Functions on regex replacement text in a StringReplacer.

2. If yes, how. If no, is there an easy way to capitalize certain sequences of characters in a string.

I'm using FME Desktop 2013, if it matters.

Not sure whether this would work in 2013 or not, but this works in 2015

StringSearcher - Regular Expression as above

AttributeCreator - create a new attribute with the matched characters turned to uppercase

Stringreplacer - use the matched characters as text to match with the new attribute created above as replacement text


Would it not be easier to use two StringReplacers in sequence in this case?

And no regular expressions, just replace Cnr with CNR and Cpr with CPR.


Would it not be easier to use two StringReplacers in sequence in this case?

And no regular expressions, just replace Cnr with CNR and Cpr with CPR.

I presume in reality the regular expression will be matching far more than 2 distinct letter sequences.


I presume in reality the regular expression will be matching far more than 2 distinct letter sequences.

Yup, I've got more than 2 sequences, and possibly more in the future. So I'd rather not add another transformer anytime a new one pops up


Not sure whether this would work in 2013 or not, but this works in 2015

StringSearcher - Regular Expression as above

AttributeCreator - create a new attribute with the matched characters turned to uppercase

Stringreplacer - use the matched characters as text to match with the new attribute created above as replacement text

This helps a lot but it's not quite what I need. Each string I take in possibly has more than one sequence within it, and this only replaces the first sequence it finds in a string.

But this does help a lot and I think with some tinkering it'll probably work, thanks.


Hi @yola, can the StringPairReplacer help you?

  • Replacement Pairs: Cpr CPR Cnr CNR

Hi @yola, can the StringPairReplacer help you?

  • Replacement Pairs: Cpr CPR Cnr CNR

Yep, perfect. Thanks!


Yep, perfect. Thanks!

Good to hear :-)

It seems that a string function within the "Replacement Text" field is evaluated before the regex replacement. That is, "@UpperCase(\\0)" will be translated to "\\0" before replacing. Result, the input string will not be changed anyway. I think this is the reason why you cannot get your expected result from the function use.


Reply