Regular Expression to Replace Some characters with Space


Can someone help with regular expression.

The requirement is the word should contain only these characters(a-z,A-Z ,space,single quote, comma, full stop, forward slash and hyphen

If there are any other special characters/characters then it should replace it with “space”.
Special characters like German Umlaut letters : “ä”, “ö” and “ü” and other characters too.


Which do you mean, replace the character with space OR replace word which contains the caharacter with space?
Can you give us some examples?


For the replacements

strReplaced =
System.Text.RegularExpressions.Regex.Replace(strText, strPattern, “”)

strText - your input Text variable
strPattern - [^A-Za-za ',.\/-]


Any characters other than these (a-z,A-Z ,space,single quote, comma, full stop, forward slash and hyphen) should be replaced with spaces.

Hi @ppr How can i check if only these characters are present and if anyother characters other than these are present i should return false.

with regex.isMatch we can do. Whenever a non valid character is matched it will return true, which we can deny

strText - your input Text variable
strPattern - [^A-Za-za ',.\/-]

Assign Activity
isValid = Not System.Text.RegularExpressions.Regex.IsMatch(strText, strPattern)

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.