[英]Javascript regex for SQL IN clause
I am pretty new to the whole regex thing and I was trying to make regex that will validate strings which contain zero or more: percentage(%) signs comma(,) signs underscore(_) signs number(0-9) signs我对整个正则表达式很陌生,我试图制作正则表达式来验证包含零个或多个的字符串:百分比(%)符号逗号(,)符号下划线(_)符号数字(0-9)符号
with max of ten numbers in a row最多连续十个数字
I came up with this: /,|%|_|[0-9]{10}/ but this regex is true for eg 123M我想出了这个:/,|%|_|[0-9]{10}/ 但是这个正则表达式对于例如 123M 是正确的
Please could somebody write the regex here and explain what each part of regex means ?请问有人可以在这里写正则表达式并解释正则表达式的每个部分的含义吗? I need the regex for SQL IN clause我需要 SQL IN 子句的正则表达式
You want to delimit the regex, so that it would have to match the entire string.您想分隔正则表达式,以便它必须匹配整个字符串。
123M
gives you a match because 123
matches and you didn't specify that you need the whole thing to match. 123M
为您提供了一个匹配项,因为123
匹配项而您没有指定需要整个匹配项。
For this you need 2 delimiters: ^
for the beginning of the string, and $
for the end of the string, turning your regex into this:为此,您需要 2 个分隔符: ^
用于字符串的开头, $
用于字符串的结尾,将您的正则表达式转换为:
/^[\\%_,]*[0-9]{0,10}[\\%_,]*$/
I also told it that any number, from 0 to 10, of these characters would be a match with {0,10}
.我还告诉它,从 0 到 10 的任何数字都将与{0,10}
匹配。 I also included the string delimiters ^
and $
.我还包括字符串分隔符^
和$
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.