正则表达式找出差异 [英] Regular expression to find the difference

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

问题描述


我想确认一下,使用正则表达式可以比较两个量与+/- 10%差异的方差吗?


是否可能?如果是,那么请让我知道它的实现方式。

感谢由Pradeep

解决方案

正则表达式不会做什么你在问。它是一个文本模式匹配器,并不了解numers本身。它识别数字字符,但程序员可以添加一串数字是或不是数字的知识。正则表达式会创建一个很好的预处理器来从字符流中提取数字,但是您必须添加代码来解释它找到的数字字符串数字,然后将您的参考值与+/- 10%差异进行比较。

Hi

I would want to confirm,using regular expression is there a way to compare two amounts with the variance of +/- 10%  difference ?


For Example: If string1 has 20 and string2 has 19,when we compare these 2 strings, the regular expression should compute the variance in percent(here we want to allow +/- 10%), then it would compare 2 strings and if it is within +/-10%, it would match else it should not match.

Is it possible? if yes then please let me know the way it can be acheived.

Thanks
Pradeep

解决方案

Regex will not do what you are asking.  It is a text pattern matcher and has no knowledge of numers per se.  It recognizes digit characters, but you the programmer add the knowledge that a string of digits is or is not a number.  Regex would make a great preprocessor to pull numbers out of a stream of characters, but you would have to add code to interpret the numeric strings it finds as numbers and then compare to your reference for +/-10% difference.


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

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