Skip to main content
Solved

How to convert uppercase to lowercase use regular expression

  • March 5, 2017
  • 6 replies
  • 176 views

taojunabc
Participant
Forum|alt.badge.img+6

FME 2017.0.0.0

I try to use StringReplacer to uppercase letters to lowercase letters, but failed.

 

Attribute:attr (has a value "ABCD")

 

Mode:Realace Regular Expression

 

Text To Replace:([A-Z])

 

Replacement Text:@LowerCase(\\1)

I also tried the @UpperCase,@Format,@PadLeft,@PadRight..., but those function seems does not work for regular expression groups (\\1) too.

String functions cannot be used in a regular expression group?

Best answer by takashi

Hi @taojunabc, I don't know if it's intentional that FME String Functions do not work for the resulting string from the StringReplacer. I remember that there was the same question before, but was not able to find out that.

Scripting may be a quick workaround in your case.

PythonCaller Script Example:

def toLower(feature):
    names = feature.getAttribute('attribute{}.name')
    if names:
        for i, s in enumerate(names):
            feature.setAttribute('attribute{%d}.name' % i, s.lower())

TclCaller Script Example:

proc toLower {} {
    for {set i 0} {1} {incr i} {
        set attr "attribute{$i}.name"
        if {![FME_AttributeExists $attr]} {
            break
        }
        FME_SetAttribute $attr [string tolower [FME_GetAttribute $attr]]
    }
}
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

itay
Supporter
Forum|alt.badge.img+18
  • Supporter
  • March 5, 2017

Hi @taojunabc, why not use the StringCaseChanger, or am I missing something?


taojunabc
Participant
Forum|alt.badge.img+6
  • Author
  • Participant
  • March 6, 2017

Hi @itay,

Sorry, I did not describe the problem clearly, My ultimate goal is to handle the list attributes, such as attribute{}.name. But StringCaseChanger can not be applied to the list attributes.

Please refer to the link below?

Lowercase PostGIS table names

In FME hub, there is a custom transformer called ListStringReplacer, It is possible to use regular expressions, but I tried it and found that it has the same behavior as StringReplacer, in order to simplify the problem, I mentioned only StringReplacer.


takashi
Celebrity
  • Best Answer
  • March 6, 2017

Hi @taojunabc, I don't know if it's intentional that FME String Functions do not work for the resulting string from the StringReplacer. I remember that there was the same question before, but was not able to find out that.

Scripting may be a quick workaround in your case.

PythonCaller Script Example:

def toLower(feature):
    names = feature.getAttribute('attribute{}.name')
    if names:
        for i, s in enumerate(names):
            feature.setAttribute('attribute{%d}.name' % i, s.lower())

TclCaller Script Example:

proc toLower {} {
    for {set i 0} {1} {incr i} {
        set attr "attribute{$i}.name"
        if {![FME_AttributeExists $attr]} {
            break
        }
        FME_SetAttribute $attr [string tolower [FME_GetAttribute $attr]]
    }
}

itay
Supporter
Forum|alt.badge.img+18
  • Supporter
  • March 6, 2017

Hi @itay,

Sorry, I did not describe the problem clearly, My ultimate goal is to handle the list attributes, such as attribute{}.name. But StringCaseChanger can not be applied to the list attributes.

Please refer to the link below?

Lowercase PostGIS table names

In FME hub, there is a custom transformer called ListStringReplacer, It is possible to use regular expressions, but I tried it and found that it has the same behavior as StringReplacer, in order to simplify the problem, I mentioned only StringReplacer.

I see, this makes sense, beside the elegant solution by @takashi the only other way I can think of is by exploding the list and applying the case change.

 


taojunabc
Participant
Forum|alt.badge.img+6
  • Author
  • Participant
  • March 7, 2017

Hi @taojunabc, I don't know if it's intentional that FME String Functions do not work for the resulting string from the StringReplacer. I remember that there was the same question before, but was not able to find out that.

Scripting may be a quick workaround in your case.

PythonCaller Script Example:

def toLower(feature):
    names = feature.getAttribute('attribute{}.name')
    if names:
        for i, s in enumerate(names):
            feature.setAttribute('attribute{%d}.name' % i, s.lower())

TclCaller Script Example:

proc toLower {} {
    for {set i 0} {1} {incr i} {
        set attr "attribute{$i}.name"
        if {![FME_AttributeExists $attr]} {
            break
        }
        FME_SetAttribute $attr [string tolower [FME_GetAttribute $attr]]
    }
}
Thank you for providing sample code,  PythonCaller or TclCaller is a relatively simple solution. 

 

 


taojunabc
Participant
Forum|alt.badge.img+6
  • Author
  • Participant
  • March 7, 2017
I see, this makes sense, beside the elegant solution by @takashi the only other way I can think of is by exploding the list and applying the case change.

 

Hi @itay,Thanks.

 

I did not think of other solution, the solution by @takashi is very simple, I decided to use his solution.