正则表达式验证 url 并且不以分号或空格结尾

我有以下正则表达式:


var regex = /https:\/\/company\.zoom\.us\/j\/.*\?pwd=.*/i;

如何修改此正则表达式以确保 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)


繁花如伊
浏览 190回答 1
1回答

慕田峪9158850

如果您不想在任何地方允许空格并且不以结尾,;那么请摆脱.*允许任何字符的正则表达式。你可以只使用:/^https:\/\/company\.zoom\.us\/j\/\S*\?pwd=[^\s;]*$/变化:\S:: 匹配 0 个或多个非空白字符[^\s;]*匹配任何不是 a;且不是空格的字符
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript