Solved

How to find letters after a period using regex and capitalize the first letter?

  • 25 March 2024
  • 4 replies
  • 89 views

Badge

Hi,

I tried to find letter after period and capitalize it using StringReplacer but it did not work. Is it possible to accomplish such a thing with the StringReplacer? For example: Condition: good. ensure continuous maintenance. The result should be like this: Condition: good. Ensure continuous maintenance.

 

Text to Replace: (^[a]|\. [a-z])

Replacement txt: .\U$1 also \U\1 won’t work.

 

Thanks

Leida

icon

Best answer by joepk 25 March 2024, 15:44

View original

4 replies

Userlevel 4
Badge +17

Hi Leida, I haven't got the /U$1 approach to work either. I used a StringSearcher to get the first letter after a period in an attribute (with RegEx: (?<=\. )[a-z]), and a StringConcatenator switched to Advanced mode with the following Expression:

@ReplaceRegularExpression(@Value(test),(?<=\. )[a-z],@UpperCase(@Value(_first_match)))

Notice the same RegEx in the String Expression.

 

Hope this helps!

Userlevel 4
Badge +30

Hi Leida, I haven't got the /U$1 approach to work either. I used a StringSearcher to get the first letter after a period in an attribute (with RegEx: (?<=\. )[a-z]), and a StringConcatenator switched to Advanced mode with the following Expression:

@ReplaceRegularExpression(@Value(test),(?<=\. )[a-z],@UpperCase(@Value(_first_match)))

Notice the same RegEx in the String Expression.

 

Hope this helps!

Great

Userlevel 4
Badge +36

It appears \1 cannot be modified.

Original Text Condition: good. ensure continuous maintenance.
Text To Replace (^[a]|\. [a-z])
Replacement Text xx@UpperCase(\1xx)
Results Condition: goodxx. eXXnsure continuous maintenance.

 

Userlevel 4
Badge +17

Nice find @geomancer, I also really can't seem to find a way to modify the result from \1.

Although using multiple transformers isn't that bad, this seems like it could be a nice addition to the string functions FME already has! 

 

Reply