[英]Javascript Regex string ends with and only contains one occurrence
I have a scenario where I need to identitify using javascript regex when a string ends with the string 47368 but not when there's multiple occurrences of 47368. For example I'd expect the following results 我有一种情况,当字符串以字符串47368结尾时,我需要使用javascript regex进行识别,但是当多次出现47368时,则不需要使用javascript正则表达式。例如,我希望获得以下结果
localhost:47368 => true
localhost:47368/abc => false
localhost:47368/abc/47368 => false
A common pattern for this use case ("match this and not that") is 此用例的常见模式(“匹配此条件而不是匹配条件”)是
^ (?! .* non-match) match
in your case: 在您的情况下:
^(?!.*47368.).*47368$
https://regex101.com/r/riDD2r/1 https://regex101.com/r/riDD2r/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.