cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
BHarris
Level VI

How do I append a literal digit (e.g., "0") after a regex capture group in JMP?

 

I'm using regular expressions in JMP Recode's "Replace String" function to transform strings like "en127" into "1270".  My approach is to capture the two digits using:

 

Find:    en(\d+)

But when I try to use:

 

Replace: \10

…it is interpreted as a reference to group 10, not group 1 followed by a literal "0".

 

Is there a way in JMP to append a literal "0" (or any literal digit) after a capture group without it being misinterpreted as a higher-numbered group?

 

Other engines (like Perl or JavaScript) let you disambiguate with braces or dollar signs (e.g., ${1}0), but JMP doesn't seem to support those.

 

I’d prefer a one-step solution, not one that requires a second replace operation.

 

Any insight on how to do this cleanly in JMP?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: How do I append a literal digit (e.g., "0") after a regex capture group in JMP?

\e (lower case e) was designed for this in a replacement. (not in a pattern match where it matches the escape character.)

https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/71...

and

Back Reference 

@shannon_conners The doc @jthi  points to has unfortunately mixed the parameter 2 matching grammar with the parameter 3 replacement grammar; \L etc has different usage in the two places. \L matches a not-lower-case character in parameter 2 and begins lower casing in a replacement string. Same for \u \U and \l. Also \E \Q only belong in parameter 3 replacements.

Craige

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: How do I append a literal digit (e.g., "0") after a regex capture group in JMP?

Away from computer so I can't look it up right now. I think you can use another escape after the \1 that won't do anything special. I think there's some escapes for upper casing and lower casing and things of that nature. Edit: if there is a code to upcase the next char that would be perfect since it would not change the next digit.

Craige
jthi
Super User

Re: How do I append a literal digit (e.g., "0") after a regex capture group in JMP?

So for example, using \L (single character that is not lowercase [^a-z])

jthi_1-1755187427028.png

Scripting Guide > Types of Data > Regular Expressions > Escaped Characters in Regular Expressions 

 

 

-Jarmo
Craige_Hales
Super User

Re: How do I append a literal digit (e.g., "0") after a regex capture group in JMP?

\e (lower case e) was designed for this in a replacement. (not in a pattern match where it matches the escape character.)

https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/71...

and

Back Reference 

@shannon_conners The doc @jthi  points to has unfortunately mixed the parameter 2 matching grammar with the parameter 3 replacement grammar; \L etc has different usage in the two places. \L matches a not-lower-case character in parameter 2 and begins lower casing in a replacement string. Same for \u \U and \l. Also \E \Q only belong in parameter 3 replacements.

Craige
BHarris
Level VI

Re: How do I append a literal digit (e.g., "0") after a regex capture group in JMP?

Yes, excellent, this appears to be the most canonical response, e.g. replace "en(\d+)" with "\1\e0".  That works, and follows the same pattern as "\U" and other special characters in replace-strings.

 

(For the probably-less-than-3 people who read this and are wondering what "\U" does, it allows you to do case changes on the replace string, e.g. if you had a list of names in a column, and wanted to change "Harris, Bryan" to "HARRIS, Bryan", you could do by with finding "(.+)(,.+)" and replacing it with "\U\1\E\2".  "\U" and "\L" are uppercase and lowercase respectively, and they operate until the next "\E".  You can also do a case-change on just the first letter with "\l" and "\u", terminating with "\e".  I cannot find any mention of these in the documentation, but it may be that I just don't know where to look.)

 

Thanks @Craige_Hales and @jthi !

Recommended Articles