简体   繁体   English

正则表达式:逗号分隔值

[英]Regex: Comma separated values

I have been trying to make a regex that will: match only if all condition are met, will not match 1 to 10 or something like it and will ignore commas. 我一直在尝试创建一个正则表达式,它将:仅在满足所有条件时匹配,不匹配1到10或类似的东西,并且将忽略逗号。

I have made (?=.*1)(?=.*5) which almost works and will match to 1,5 as it is meant to but will also match to 10,5 , 10,50 and 1,50 . 我做了(?=.*1)(?=.*5)几乎工程,并将匹配到1,5 ,因为它意味着也将匹配到10,510,501,50 I can not work out how to stop this. 我无法解决如何停止这种情况。 So my question is how do I get the regex to know the difference between numerals and a single digit. 所以我的问题是我如何让正则表达式知道数字和单个数字之间的区别。

使用\\b使它与数字周围的单词边界匹配。

(?=.*\b1\b)(?=.*\b5\b)

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

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