正则表达式为“0.000%”。 [英] Regular Expression for "0.000%"

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

问题描述

我想知道字符串的正则表达式以%符号结尾(例如:0.000%这是我的字符串)任何人都可以告诉我答案....

解决方案

尝试:

 \d + \.\d {3}%


它匹配一个或多个数字,小数点,3位数字,字符串末尾的百分比。



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


如果您处理必须运行的软件,解析数字可能会欺骗您变化的文化。

小数分隔符在所有文化中都不一样。



取决于你从哪里得到你的字符串(例如它是本地化或文化不变?)那么你必须遵循不同的方法。



如果它是文化不变的,请采取其他建议的方法之一。

如果已本地化,让系统解析数字,即在%符号前面取非空格文本并传递它到 TryParse 方法。

例如

  string  s =   ...; 
var match = Regex.Match(s, @ ^ \s *(。*?)\s *%* \s

I want to know the regular expression for the string ends with % symbol(Ex:"0.000%" this is my string ) could any one tell me the answer....

解决方案

Try:

\d+\.\d{3}%


It matches 1 or more digits, decimal point, 3 digits, percent at the end of the string.

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


Parsing numbers might fool you if you deal with software that must run under variing cultures.
The decimal separator is not the same on all cultures.

Depending on where you got your string from (e.g. is it localized or culture invariant?) then you must follow differing approaches.

If it is culture invariant, take one of the other suggested soulutions.
If localized, let the system parse the number, i.e. take the non-space text before the % symbol and pass it to the TryParse method.
E.g.

string s = "...";
var match = Regex.Match(s, @"^\s*(.*?)\s*%\s*


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

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