You are viewing limited content. For full access, please sign in.

Question

Question

Regex to add space before Capital Letters

asked on July 9, 2018

So i have a string that has no spaces, but each word in the string is capitalized. For example the string could contain "JohnTonySmith" and I would like to be able to add a space before the capital letters so that it turns into "John Tony Smith" is this possible to do with regex in Quick Fields?

0 0

Replies

replied on July 9, 2018 Show version history

Hi Joshua, 

 

I think you can accomplish this with a series of regular expressions.  At least if the strings  have a consistent number of words.  The expressions would look like this, to break it down.  Then you could put it back together with the spaces. 

 

([A-Z].*)[A-Z].*[A-Z].*

[A-Z].*([A-Z].*)[A-Z].*

[A-Z].*[A-Z].*([A-Z].*)

Capture.PNG
Capture.PNG (43.03 KB)
1 0
replied on July 9, 2018

Regex only works with existing data, so as such it can't add to it. But check out the Substitution process which allows you to use regex to break up your string into "John", "Tony", "Smith" and then built it back up from the 3 values with space using match groups.

0 0
replied on July 9, 2018 Show version history

If you have substitution, you can create a substitution rule for each letter A-Z.  So "A" is replaced with " A", etc.  Mack sure to check the box to match case and the box to replace the input with the result.

In my sample, I just do the 3 letters of your sample name

The data is in a barcode that is read into token %(Barcode 1) by my QF session.  Then after I run the substitution on that token, to use the token data, apply a trim function.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.