Reputation: 959
I am looking to convert a part of a string which is substringof('has',verb) into contains(verb,'has')
As you can see, what is changing is just substring to contains and the two parameters passed to the function reversed.
I am looking for a generic solution, by using regex. Preferably using tags. i.e once i get two matches, i need to be able to reverse the matches by using $2$1 (This is how i remember doing this in perl)
Upvotes: 1
Views: 596
Reputation: 30995
You can use a regex like this:
.*?\((.*?),(.*?)\)
Then you can use a string replacement like this:
contains(\2,\1) or
contains($2,$1)
Btw, if you just want to change the substringof
, then you can use:
substringof\((.*?),(.*?)\)
Upvotes: 0
Reputation: 391396
You can use this regular expression code:
var re = new Regex(@"substringof\('([^']+)',([^)]+)\)");
string output = re.Replace(input, @"contains($2, '$1')");
Upvotes: 1