如何为+/-编写正则表达式 [英] How to write the regexp for +/-

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

问题描述

我想写一个Regexp for

 +/- 





我试过这样

((ChrW(043)/ ChrW(045))



但它根本不起作用。



专家建议我获得解决方案



提前致谢

解决方案

假设你的意思是加或减数字前面的例子:

 123.45 
+123.45
-123.45

然后很简单:

 [+  - ] 

允许或不允许:

 [+  - ]?

不允许后跟浮点数:

 [+  - ]?\ d +(\.\d +)


I want to write the Regexp for

+/-  



I tried like this

((ChrW(043)/ChrW(045))


but it did not not works at all.

Experts Suggest me to get the solution

Thanks in advance

解决方案

Assuming you mean "plus or minus" infront of a number for example:

123.45
+123.45
-123.45

Then it's simple:

[+-]

To allow either or nothing:

[+-]?

To allow neither followed by a floating point number:

[+-]?\d+(\.\d+)


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

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