The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
"Split Text Case - RegEx dropping letters"
I have some text that comes in different cases sometimes tokens are TextendNewtext others textendNewtext I found this regex online for python
([A-Z])([A-Z])([a-z])|([a-z])([A-Z])
but when I apply it to my dataset using the replace tokens operator and ([A-Z])([A-Z])([a-z])|([a-z])([A-Z]) replaced by $1 $2 I get
Texten ewtext
I'm far from an expert in regex in any flavour but can anyone help me resolve this
([A-Z])([A-Z])([a-z])|([a-z])([A-Z])
but when I apply it to my dataset using the replace tokens operator and ([A-Z])([A-Z])([a-z])|([a-z])([A-Z]) replaced by $1 $2 I get
Texten ewtext
I'm far from an expert in regex in any flavour but can anyone help me resolve this
Tagged:
0
Answers
is there a way in rapidminer to handle CamelCaseTextOfVariousLengths and split it into tokens?
why not simply use replace and replace capital letters with white space followed by the latter? Seems to work
~Martin
Dortmund, Germany
In the regular expression
([A-Z])([A-Z])([a-z])|([a-z])([A-Z])
all the parentheses are numbered. You're trying to replace by the value coming from the first and second parentheses, which would be two capital letters if your text matched that. It doesn't, so it goes to the second (alternate) match after the pipe symbol. But the contents of those parentheses are not in the replacement string. They would be $4 and $5.
Martin's approach seems to be what you want.
Hi Martin, hi everybody
I am facing the same problem as mob. Unfortunately I couldn't solve it using your comment from 02-01-2016.
Problem:
I want to separate the following text: "PleaseSeparateMeByCapitalLetters" into "Please Separate Me By Capital Letters"
I tried to use the Replace Tokens operator
- replace what:[A-Z]
- replace by: $1
However the result is " lease eparate e y apital etters".
Thanks in advance for your help
Andreas
The $1 refers to a "capture expression". You define capture expressions with (). If that's not in the replace what part, then $1 will be empty.
Try this : ([A-Z])(.) ,replace by $1$2 and ensure there is a space before $1. It also adds a space before the first word but you can remove that one again by doing a second regex or trim the string.
so like this :
<parameter key="replace_what" value="([A-Z])(.)"/>
<parameter key="replace_by" value=" $1$2"/>
Probably not the most sexy solution but plain simple sometimes does the trick also.
Thank you !!!