JavaScript RegExp Custom URL validation with ${protocol}
JavaScript RegExp Custom URL validation with ${protocol}
我在通过正则表达式时遇到了一些困难。 我的表达式应该验证一个网址。对于协议,它将允许三个值:http,https和${protocol}。
因此,以下是一些有效网址的示例:
- http://someurl.com
- https://someurl.com
- ${协议}://someurl.com
到目前为止,前两个通过我当前的 RegExp,但 ${protocol} 不会通过。 有人可以尝试帮助我调试它并查看为什么我的 ${protocol} 没有通过吗?
这是我到目前为止的正则表达式:
var urlRegEx = new RegExp('('$'{protocol'}|http(s)?)://(([A-Za-z0-9-]+'.)*([A-Za-z0-9-]+'.[A-Za-z0-9]+))+((/?)(([A-Za-z0-9'._'-]+)(/){0,1}[A-Za-z0-9.-/]*)){0,1}', 'i');
使用
RegExp
时,您必须将所有反斜杠写入两次:(''$''{protocol
等。
(来自THG435的评论)
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Modify Javascript with C#
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- JavaScript RegExp Custom URL validation with ${protocol}
- ARP protocol with node.js