Skip to main content
Solved

Regex to replace PascalCase

  • July 6, 2018
  • 1 reply
  • 116 views

ld
Participant
Forum|alt.badge.img+1
  • Participant

Hi all

I have an attribute whose values are all written in PascalCase, for example "PleaseHelpMeOutHere".

I'd like to add a space at any capital letter, making a more readable string "Please Help Me Out Here". I don't need to preserve the original attribute.

To make it a little more complicated, some attributes have more than one capital letter, which I'd like to preserve (except for the last capital, which denotes a new word). For example "SOSHelpMeOutHere" becomes "SOS Help Me Out Here"

My guess would be that using a StringReplacer with Regex would work, but Regex is a foreign language to me. I could always use a PythonCaller, but I'd prefer to avoid that if possible.

Thanks

Best answer by takashi

Hi @ld, assuming that only English alphabet characters would appear, the StringReplacer with this setting might help you.

  • Mode: Replace Regular Expression
  • Case Sensitive: Yes
  • Text To Replace: (?<=.)([A-Z][a-z])
  • Replacement Text: <space>\\1

Replace the '<space>' with an actual space character.

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

1 reply

takashi
Influencer
  • Best Answer
  • July 6, 2018

Hi @ld, assuming that only English alphabet characters would appear, the StringReplacer with this setting might help you.

  • Mode: Replace Regular Expression
  • Case Sensitive: Yes
  • Text To Replace: (?<=.)([A-Z][a-z])
  • Replacement Text: <space>\\1

Replace the '<space>' with an actual space character.


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