0
我有一个图像url正则表达式正在使用ng-pattern
指令来验证表单上的图像。图像的URL正则表达式,以适应特殊的urll
目前我正在努力适应类似https://google.com.png
的情况。任何帮助将非常感激。
正则表达式:
'^((?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)[email protected])?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?)\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF)$'
更好的观看位置:
https://regex101.com/r/dH1wT6/1
可能重复[什么是一个很好的正则表达式来匹配一个URL?](http://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a- url) – nicael
您只需使用正则表达式来匹配URL,然后将其附加到此正则表达式,无论您需要什么。 – nicael