用于解析图像大小的正则表达式 [英] Regex for parsing image size

查看:107
本文介绍了用于解析图像大小的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建正则表达式以解析大小时遇到问题,除了用逗号分隔。



Ex。



34,34 =成功

34,34a =失败



我只想要两个数字的匹配,我已经尝试了正则表达式



 Regex.IsMatch(输入,([0-9 ],[0-9]));





几乎可行,但匹配第二对后的字母。



我找了一些例子,但大多数都是用javascript编写的,我几乎可以肯定C#的正则表达式是不同的。

我也知道有其他选择将字符串解析为大小,但我正在努力寻找正常工作的正则表达式。



祝你好运,



austinbox

解决方案

 Regex.IsMatch(输入,< span class =code-string> ([0-9],[0-9])); 



这个表达式确实找到了一个字符串中[numeric],[numeric]的匹配项,但对输入的其余部分没有任何意义......

所以 A 1,2,b 也被认为是有效的。

你必须包括开始结束标记,告诉你正在寻找一对用逗号分隔的数字,而不是更多...

 Regex.IsMatch(输入,  ^([0-9],[0-9])

);


I'm having a problem with creating a regular expression to parse a Size, except delimited by a comma.

Ex.

34,34 = success
34,34a = fail

I only want a match of two numbers, I've tried the regular expression

Regex.IsMatch(input, "([0-9],[0-9])");"



And almost works, but matches letters succeeding the second pair.

I've looked for examples, but most are in javascript and I've almost sure C#'s regex is different.
I also know there are alternatives to parsing a string into a Size, but I'm striving to find a working regex.

Best regards,

austinbox

解决方案

Regex.IsMatch(input, "([0-9],[0-9])");


This expression does find a match for [numeric],[numeric] inside a string but does nothing about the rest of the input...
so a1,2,b also considered valid.
You have to include the begin-end marks to tell that you are looking for a pair of numbers separated by comma and nothing more...

Regex.IsMatch(input, "^([0-9],[0-9])


");


这篇关于用于解析图像大小的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆