开发者

What is the problem with this regular expression?

开发者 https://www.devze.com 2023-02-04 22:20 出处:网络
I have the following code: Regex scale = new Re开发者_Python百科gex(@\"/^(\\d+)x(\\d+)-([a-zA-Z0-9]+(\\.jpg)?)$/\");

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)?)$"
0

精彩评论

暂无评论...
验证码 换一张
取 消