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

Question

Question

Regex, select whole string in one match except the /.

asked on June 9, 2022 Show version history

I need some help with regex with this test string:

Kershing_User ID/Electronic Delivery_6ZZ138429_ 3142-999999__1

I want one match to select everything except the forward slash, so this would be acceptable:

Kershing_User IDElectronic Delivery_6ZZ138429_ 3142-999999__1

Even better would be to return this with a substitution of a _. 

Kershing_User ID_Electronic Delivery_6ZZ138429_ 3142-999999__1

I know how to do lookarounds and can individually match the part before and after the /, but not all in one go. Anything else I have tried has matched it in two pieces, and thus doesn't work the LF Token Dialog. 

This does the before: 
 

.*(?=\/)

This does the after: 

(?<=\/).*

 

0 0

Answer

SELECTED ANSWER
replied on June 9, 2022

Are you doing this in Workflow?  Because if you are, the option to replace the slash with underscore could be done with the Token Calculator activity and a SUBTITUTE function, like this:

1 0

Replies

replied on June 9, 2022

You should be able to get the option to remove the slash with something like this:   [^\/]*

This is technically finding two matches, but then combining them with no space - which is a setting in the Pattern Matching activity in Workflow.

1 0
replied on June 9, 2022

Wow, this is gold as well. I overlooked this when making the reply below about the SUBSTITUTE below. Thanks again. 

1 0
replied on June 9, 2022

Thanks, Matt. That was it. Easy and intuitive. You should get my day of pay!

If you don't mind, what functions within token calculator do you find you use the most? 

Do you know if it is still possible with regex though? 

0 0
replied on June 9, 2022

I probably use SUBSTITUTE more than anything else on the token calculator.

I also use a lot of the other string manipulating ones like LEFT, RIGHT, MID quite often.

And of course numerical calculations ones like SUM, ROUND, AVG, etc.

I don't think it's possible with pure RegEx to do a replace, but you can get everything except a certain character as in my other reply - the trick there is just whether or not the tool you are using treats everything before/after the character as one value or multiples.  In the case of Workflow, it is multiples but of course gives us the option to combine those back together.

1 0
replied on June 13, 2022

Here's a nice free tool for building and testing regular expressions

https://regexr.com/

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

Sign in to reply to this post.