有关正则表达式的查询 [英] Query regarding regular expression

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

问题描述

大家好,

我正在使用正则表达式来验证C#.net应用程序中的数字字段.

我想接受14.2(NNNNNNNNNNNNNNNN.NN)格式的十进制数据,为此我正在使用"\ d {0,14} [.] {0,1} \ d {0,2}".问题在于该表达式也匹配负值.

请提出解决方案.

提前致谢.

Gitika

Hi All,

I am using a Regular expression to validate a numeric field in my C#.net application.

I want to accept decimal data in the format 14.2 (NNNNNNNNNNNNNN.NN), for which I am using "\d{0,14}[.]{0,1}\d{0,2}". The problem is this expression is matching negative values also.

Please suggest a solution.

Thanks in advance.

Gitika

推荐答案

尝试在前面添加"^"(并在末尾添加"
Try adding ''^'' to the front (and ''


")-它指定数字必须在字符串的开头.您还需要转义"[.]"中的.'',否则它将与任何字符匹配
试试:
'' to the end) - it specifies that the digits must be at the start of the string. You also need to escape the ''.'' in the "[.]" as otherwise it will match any character
Try:
^\d{0,14}(\.\d{0,2}){0,1}




获取 Expresso [ ^ ]-它是免费的,它可以检查并生成正则表达式.



Get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions.


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

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