简体   繁体   English

正则表达式匹配任何单词组合但不是单个小数

[英]Regex to match any combination of words but not a single decimal

I have a long regex containing (?:\\S+ ){0,4} 我有一个很长的正则表达式包含(?:\\S+ ){0,4}

That should match: (it's already doing this correctly) 这应该匹配:(它已经正确地这样做了)

2 Terry White 
Tramal 100 
Asmol 2.5 
2.5% 

or anything matching that, except a single decimal or price. 或任何匹配的, 除了一个小数或价格。

It should not match: (I don't know how to do this exception) 它不应该匹配:(我不知道怎么做这个例外)

870
6.75
$17.60

Is that even possible? 这甚至可能吗?

Thanks everyone for your input. 谢谢各位的意见。 Just FYI for those who are curious, here is one of the shortest "long regex" it is used in (you can find it near the end) 对于那些好奇的人来说,仅供参考,这是其中最短的“长正则表达”之一(你可以在最后找到它)

^ {0,5}(\d{4}[A-Z]) +((?:\S+ )+(?: {0,10}K\+)?) *(\.\.|\d+) +(?:[A-Z#\*] *)?(\.\.|\d+(?:\.\d{1,4})?) +(?:[ab] *)?((?:\S+ ){0,4}) *([A-Z]{2}) {0,10}$

I'm not sure what you mean by "a single decimal" since your first failing example appears to be an integer, but you might try: 我不确定你的“一个小数”是什么意思,因为你的第一个失败的例子似乎是一个整数,但你可能会尝试:

^(?!\$?\d+(?:\.\d+)?$).+$

Based upon your comments, I'm thinking a negative lookbehind might be more of what you are looking for: 根据你的评论,我认为负面的观察可能更多的是你正在寻找的:

(?<!\$?\d+(?:\.\d+)?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM