简体   繁体   English

Javascript正则表达式字符串以结尾,并且仅包含一次

[英]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.

相关问题 正则表达式在 Javascript 中的字符串末尾精确匹配一次出现的字符 - RegEx to match exactly one occurrence of character at the end of string in Javascript 正则表达式字符串以不能在 Javascript 中工作结束 - Regex string ends with not working in Javascript javascript 中的正则表达式对以某个字符串 X 结尾并包含某个字符串 Y 的字符串使用 RegExp 构造函数 - Regex in javascript using RegExp contructor for the strings that ends with some string X and contains some string Y javascript正则表达式:字符串包含这个,但不是那个 - javascript regex: string contains this, but not that 正则表达式接受最后只出现一次“%”的数字 - Regex for accept number with only one occurrence of '%' at last JavaScript正则表达式仅捕获最后一次出现的组 - JavaScript regex captures only the last group occurrence 正则表达式检查字符串是否仅包含字母数字字符和空格 - javascript - Regex to check if string contains Alphanumeric Characters and Spaces only - javascript 如果字符串仅包含唯一字符,则使用JavaScript进行正则表达式测试 - Regex test in JavaScript if a string contains only unique characters javascript正则表达式浮点数,以字符串结尾 - javascript regex float number which ends with string 长度为N的字符串包含至少一个字母x的javascript正则表达式 - javascript regex for string of length N that contains at least one letter x in it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM