Escaping special regex characters?


#1

I am trying to assign a value to a variable (using Assign) however my formula will not validate.

the regex string is [^\\]+(?=\.xlsb$)

I have tried all of the following with no success:

Regex.Match(file_address,[^\\]+(?=\.xlsb$)).Value
Regex.Match(file_address,"[^\\]+(?=\.xlsb$)").Value
Regex.Match(file_address,@"[^\\]+(?=\.xlsb$)").Value
Regex.Match(file_address,"[^\\]+(?=\.xlsb$)").Groups(0).Value
Regex.Match(file_address,"[^\\]+(?=\.xlsb$)").Groups(1).Value

The problem appears to be around the + character.

Any help would be much appreciated

Alternatively if there is a way to get UIpath to play nicely with excel binaries that would be useful too.

Thanks


#2

The expression looks correct. Have you tried including a multiple lines flag, in order to ensure that the $ validates?

System.Text.RegularExpressions.Regex.Match(file_address, “[^\]+(?=.xlsb$)”,system.Text.RegularExpressions.RegexOptions.Multiline).Value

Useful sites:
http://regexr.com/
https://msdn.microsoft.com/en-us/library/yd1hzczs(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-6