cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Workflow Hero

How To Replace a Group With RegEx?

Jump to solution

Hey folks!

(And probably, specifically Marian Hatala‌, ‌)

I'm not great with RegEx. I want to use the Replace() functionality to, if a single line of text matches a RegEx pattern, to turn it to a word. 

Using an example here, but basically:

SLT:  32.44

RegEx: ^(\d\d\.)\d\d$

Now, if I were to put that RegEx into the "Regular Expression" validation portion of the SLT, it's valid - that's rad. Great. If not, maybe just the number appears, or maybe it's blank. Whatever, doesn't matter to me.

BUT.

I want to put it into this calculated field as, for example, replace(SLT, "^(\d\d\.)\d\d$", "yes this format is correct") 

The goal is to have a specific word appear if the formatting matches the RegEx. 

Thanks for any help that can be offered!

(The overall goal here, if you're curious, is that we have specific validation formatting required if it's imperial vs metric, but it's also all within the same text field. If you have better ideas, I am all ears.)

Labels: (3)
0 Kudos
Reply
4 Replies
Workflow Hero

Re: How To Replace a Group With RegEx?

Jump to solution

To use regex pattern within replace() function (aka in javascript) you have to double each backslash, like:  ^(\\d\\d\\.)\\d\\d$

not sure what exactly you mean with validation for imperial vs. metric.

But if each can be in different format, you shuold be able to achieve it with regex validation. validation expression would look like: (pattern1|pattern2)

ie. each pattern would validate  one type of formatting

Reply
Workflow Hero

Re: How To Replace a Group With RegEx?

Jump to solution

Tested, success! Thanks <3

e: Actually -- it seems to be picking up the first pattern in my group but not the latter. Here's my full calc:

if(nIdentifyUnits == "Metric", replace(nMinDepositedWeldMetal,"^(\\d\\d\\.)\\d\\d$|^(\\d\\.)\\d\\d$","Valid"), replace(nMinDepositedWeldMetal,"^(\\d.)\\d\\d\\d$","Valid"))

When it's "metric", 55.55 is valid but 5.55 isn't -- I thought that the | would act as "or" (it does in a reg ex right in the control validation itself) and use either of the captures. Any thoughts on that?

0 Kudos
Reply
Workflow Hero

Re: How To Replace a Group With RegEx?

Jump to solution

PS: Marian update your avatar already

0 Kudos
Reply
Workflow Hero

Re: How To Replace a Group With RegEx?

Jump to solution

yes, "|" means "or" 

regex pattern(s) are correct. haven't you (accidentally) typed/copied a space around figures?

btw, you could prettify/simplify your regex patterns like

if(nIdentifyUnits == "Metric", replace(nMinDepositedWeldMetal,"^\\d{1,2}\\.\\d{2}$","Valid"), replace(nMinDepositedWeldMetal,"^\\d.\\d{3}$","Valid"))

and if haven't insisted on what format is for what unit system overall formula could be reduced to

replace(nMinDepositedWeldMetal,"^\\d{1,2}\\.\\d{2}$|^\\d\\.\\d{3}$","Valid")
Reply