Regular expression matching and replacing

Need separate answers for the following:

  1. How do I read a string and return a boolean whether it matches a regular expression or not?
    This should be in a single line for use in the If Activity.

  2. How do I replace the part of the string which contains the regular expression?



In If activity, readString.contains(“search Text”)
Then do next step
Else stop

Use Str.Replace(“old value”, “new value”)

Hi, “search text” and “old value” needs to fulfil conditions of the regular expression…

It needs to be flexible to accommodate variations so I need to use a regular expression instead of a fixed string

e.g. 109-Company A, 110-CompanyB, 111-5Company C

Currently using regular expressions [0-9]±[^ ]+ and [0-9]±[0-9]*


Try below one:

Dim myString As String = "The cat in the hat dog"
Dim regex = New Regex("\bcat\b.*\bdog")
Dim match = regex.Match(myString)
If match.Success Then
End If


To replace, try following one


ResultString = Regex.Replace(yourString, "(-*\d+;*)+", "newValue")

Here, use your regular expression


Does this method replace the matching part of the string or the whole string?


It will replace matching part only.

For your First Answer, You can also use the activity “Is Match”

it will return bool.

For the Secount Part.

You can use If condition and can replace if it matches.