Skip to main content
Solved

Regex to replace PascalCase

  • July 6, 2018
  • 1 reply
  • 157 views

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

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.

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.

1 reply

takashi
Celebrity
  • 7843 replies
  • 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.