What is the problem with this regular expression?
I have the following code:
Regex scale = new Re开发者_Python百科gex(@"/^(\d+)x(\d+)-([a-zA-Z0-9]+(\.jpg)?)$/");
Match m = scale.Match(alias);
if (m.Success)
{
//do something
}
alias contains, 10x10-uu.jpg
and is not matching - success is always false.
What am I doing wrong? :-) Thanks.
Delimiters are not necessary in .NET regexes, these are only found in PCRE and JavaScript regexes. Your forward slashes are being treated literally, meaning you get /^
and $/
, which make no sense.
@"^(\d+)x(\d+)-([a-zA-Z0-9]+(\.jpg)?)$"
精彩评论