I have to use regular expressions in a c# application and I try to use it as a string to use regex.match method. My regular expression is like id="(tt[0-9]+)\|imdb and I convert it to string like "id\"(tt[0-9]+)\\|imdb" but it doesn't work. Do you have any solutions or applications that convert regexes to strings??
You can drop the escaping and use a @ sign.
@"id=""(tt[0-9]+)\|imdb"
Note: you have to double the doublequotes
Not sure what you are trying to accomplish, so I am going down a different path then the other posts.
The Regex.Match method should take the String you are trying to match against, it sounds like you are attempting to go backwards from a constructed RegEx to a String. If that is the case simply call ToString() on the RegEx to get the passed in expression.
If you are simply trying to get the expression as a String then the pattern var below would so that making use of the @ as mentioned in the other posts. Either way though, the RegEx itself should contain the pattern you want to match against.
string text = "91919182389348487";
string pattern = @"id=""(tt[0-9]+)\|imdb";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
Match m = r.Match(text);
...
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