16

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:

Example 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

2
  • Is the ! always in the string? Commented Oct 24, 2013 at 17:22
  • Please explain your input and expected output with more details. Commented Oct 24, 2013 at 17:23

3 Answers 3

35
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+)","");
Sign up to request clarification or add additional context in comments.

3 Comments

Though I wouldn't bet my life on it, since this question is so poorly asked, I believe MyUDF could be any string.
@neoistheone indeed..edited the ans..Though op should come clear on this
Sorry about it. MyUDF is simply a function name, so only has letters. thanks
2

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, @"!(.*)?\(");

Comments

-1

The feature you want, if you are dealing with file paths, is in System.Path.

There are many methods there, but that is one of it's specific purposes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.