简体   繁体   中英

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

I have a long regex containing (?:\\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+)?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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