Regex Character

Hi All,

I am using an regex expression where I need to remove special character from file name. I have used the below regex expression but it is removing the dot also. I want the dot in my file name .
System.Text.RegularExpressions.Regex.Replace(file_Name,"[^A-Za-z0-9 -]“,”")
(Before Regex)file_Name= 14638_Invoice.440992_1

After using regex file_Name = 14638_Invoice440992_1_

I want to keep the dot after Invoice in my file name .

Hey @marina.dutta
try to use:
System.Text.RegularExpressions.Regex.Replace(file_Name, "[^A-Za-z0-9 ._-]", "")



HI @marina.dutta ,

Give us some more information
is the file name is same all the time or it will chnage
if it chaninging try to give some different kind of examples


you can use below expression

System.Text.RegularExpressions.Regex.Replace(file_Name, “[^A-Za-z0-9 .-]”, “”)

With this corrected code, the regular expression [^A-Za-z0-9 .-] will match any character that is not a letter (uppercase or lowercase), digit, space, dot (. ), or hyphen (- ). This way, the dot in the file name will not be removed.

Hi @marina.dutta

Use Below Regex Expression in Assign Activity

System.Text.RegularExpressions.Regex.Replace(file_Name, “[^a-zA-Z0-9._]”, “”)

Hope it will helps you :slight_smile:

Hi @marina.dutta

You can use this regular expressions. This expression won’t replace the dot.

Output = System.Text.RegularExpressions.Regex.Replace(Input,"[^A-Za-z0-9 ._-]","")


1 Like


If i want to keep the brackets. This expression is removing the brackets .what will be the regex expression? In the below expression I need to keep the brackets

System.Text.RegularExpressions.Regex.Replace(file_Name, “[^A-Za-z0-9 ._-]”, “”)


If I need to keep the brackets what will be the regex expression

System.Text.RegularExpressions.Regex.Replace(Input,“[^A-Za-z0-9 ._-]”,“”)

ok. Let’s try to use it:
System.Text.RegularExpressions.Regex.Replace(file_Name, "[^\w .\-\[\]\(\)]", "")

1 Like


ok but it should not contain any forward or backward slash. brackets, dot is allowed


Try this:

Output = System.Text.RegularExpressions.Regex.Replace(Input,"[^A-Za-z0-9 ()._-]","")


1 Like

Please try it:
System.Text.RegularExpressions.Regex.Replace(file_Name, "[^\w\-\.\[\]\(\)]", "")


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