I want to find paths from a string and remove them
e.g. string1 = "'c:\a\b\c'!MyUDF(param1, param2,..) + 'c:\a\b\c'!MyUDF(param3, param4,..)..."
, I'd like a regex to find the pattern '[some path]'!MyUDF
, and remove '[path]'.
Thanks
Edit e.g. input string1 ="'c:\a\b\c'!MyUDF(param1, param2,..) + 'c:\a\b\c'!MyUDF(param3, param4,..)"; expected output "MyUDF(param1, param2,...) + MyUDF(param3, param4,...)" where MyUDF is a function name, so it consists of only letters
input=Regex.Replace(input,"'[^']+'(?=!MyUDF)","");
In case if the path is followed by ! and some other word you can use
input=Regex.Replace(input,@"'[^']+'(?=!\w+)","");
Alright, if the !
is always in the string as you suggest, this Regex !(.*)?\(
will get you what you want. Here is a Regex 101 to prove it.
To use it, you might do something like this:
var result = Regex.Replace(myString, @"!(.*)?\(");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With