A regex that validates a web address and matches an empty string?

前端 未结 3 1776
一个人的身影
一个人的身影 2020-12-18 13:06

The current expression validates a web address (HTTP), how do I change it so that an empty string also matches?

(http|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+         


        
3条回答
  •  北海茫月
    2020-12-18 13:29

    Expr? where Expr is your URL matcher. Just like I would for http and https: https?. The ? is a known as a Quantifier -- you can look it up. From Wikipedia:

    ? The question mark indicates there is zero or one of the preceding element.

提交回复
热议问题