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

Question

Question

Using "Allow tokens in the pattern", the token values contain Regex Characters - what to do?

asked on April 21, 2021 Show version history

In Pattern Matching, we have the option of "Allow tokens in the pattern". But, I can see the case where the token value contains a regex special character like \^.? and so on.

Is there a way to encode the token so that the special characters are themselves escape'd away, and just treated like a literal?

0 0

Answer

SELECTED ANSWER
replied on April 28, 2021

Workflow doesn't seem to have a Regex Escape function, but VB.NET does.

Add a script task ahead of the regex lookup. Import System.Text.RegularExpressions, then use Regex.Escape() to escape any Regex special characters from the token value and return the results as a new token to use as the pattern in the Pattern Matching activity.

 

In the Import section:

Imports System.Text.RegularExpressions

In the Execute sub:

Dim searchFor AS String, searchForRegex AS String
searchFor = GetTokenValue("searchForTokenName")
searchForRegex = Regex.Escape(searchFor)
SetTokenValue("searchForRegexTokenName",searchForRegex)

Then just update the Pattern in the Pattern Matching activity from %(searchForTokenName) to %(SearchForRegexTokenName).

1 0

Replies

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

Sign in to reply to this post.