[英]Regex to validate url AND does not end in semicolon or space
I have the following regex:我有以下正则表达式:
var regex = /https:\/\/company\.zoom\.us\/j\/.*\?pwd=.*/i;
How can I modify this regex to ensure that the url string does not end in a semicolon or space?如何修改此正则表达式以确保 url 字符串不以分号或空格结尾?
https://company.zoom.us/j/xxxxx?pwd=zzzzz //Should pass
https://company.zoom.us/j/xxxxx?pwd=zzzzz //Should fail (ends in a space after the z)
https://company.zoom.us/j/xxxxx?pwd=zzzzz; //Should fail (ends in a semicolon)
https://company.zoom.us/j/xxxxx?pwd=zzzzz; //Should fail (ends in a space after the semicolon)
If you don't want to allow whitespaces anywhere and not end with ;
如果您不想在任何地方允许空格并且不以
;
结尾;
then get rid of .*
from regex that allows any character.然后从允许任何字符的正则表达式中删除
.*
。
You may just use:你可以只使用:
/^https:\/\/company\.zoom\.us\/j\/\S*\?pwd=[^\s;]*$/
Changes:变化:
\\S:
: matches 0 or more of any non-whitespace character \\S:
:匹配 0 个或多个任何非空白字符[^\\s;]*
matches any character that is not a ;
[^\\s;]*
匹配任何不是;
字符and not a whitespace
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.