[英]Regex - Match a string pattern
I need a regex that will match only strings of this kind 我需要一个仅匹配这种字符串的正则表达式
Match these strings: 匹配以下字符串:
edo-apple-iphone-5s-i-gold-16
DON'T match these strings: 不要匹配以下字符串:
edo-apple-iphone-5s-i-gold-16-edo-staff-connect-24
The main difference between the 2 strings is either a connect-24
OR handset-24
added to the end of the string 2个字符串之间的主要区别是在字符串末尾添加了connect-24
或handset-24
I have written a Regex, but it seems to match both strings: 我写了一个正则表达式,但似乎匹配两个字符串:
^edo[a-z1-9\-]*
How do i modify this to not accept if connect-24
OR handset-24
is in the string? 如果在字符串中connect-24
或handset-24
我如何修改它以不接受?
Here is a regular expression that would satisfy the requirement as stated: 这是一个满足以下要求的正则表达式:
.{32,}
Clearly, the strings you want to match are all longer than the ones you don't want to match. 显然,您要匹配的字符串都比您不想匹配的字符串长。 This regex matches only those strings that are 32 characters or longer, while edo-apple-iphone-5c-i-yellow-32
, the longest non-matching string, has only 31 characters. 此正则表达式仅匹配32个字符或更长的字符串,而最长的不匹配字符串edo-apple-iphone-5c-i-yellow-32
只有31个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.