Skip to main content
Solved

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


leida
Observer
Forum|alt.badge.img+1

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

Best answer by joepk

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!

View original
Did this help you find an answer to your question?

4 replies

joepk
Influencer
Forum|alt.badge.img+20
  • Influencer
  • Best Answer
  • March 25, 2024

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!


danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Evangelist
  • March 25, 2024
joepk wrote:

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


geomancer
Evangelist
Forum|alt.badge.img+47
  • Evangelist
  • March 26, 2024

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.

 


joepk
Influencer
Forum|alt.badge.img+20
  • Influencer
  • March 26, 2024

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


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