Reputation: 21522
I would like to remove part of a string. It would have to match "/*/cms/" (without the quotes). * would be a wildcard equaling anything except a / key. The string could have more than one match to be removed.
This would have to be done in c#. I think this can be done with a regex? But I'm not sure.
Upvotes: 1
Views: 844
Reputation: 4939
Look up Regex.Replace. Hacking the example quickly:
string pattern = "/[^/]+/cms/";
string replacement = "";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Upvotes: 0
Reputation: 1769
using System.Text.RegularExpressions;
Regex.Replace("/some example text/cms/;/some more text/cms/text/cms", "/[^/]+/cms/", "")
Use /[^/]+/cms/
if something must be between the first and second /
's, use /[^/]*/cms/
if //cms/
is a valid match.
Upvotes: 1
Reputation: 4384
The regex to match that is /[^/]*/cms/
, used like this: new Regex("/[^/]*/cms/").Replace(yourString, "")
Upvotes: 2