Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Javascript正则表达式转换为Typescript正则表达式_Javascript_Regex_Typescript_Regex Negation - Fatal编程技术网

将Javascript正则表达式转换为Typescript正则表达式

将Javascript正则表达式转换为Typescript正则表达式,javascript,regex,typescript,regex-negation,Javascript,Regex,Typescript,Regex Negation,我有一个正则表达式来检查inputText是否为有效的url格式。 而且工作几乎很好: checkUrlFormat() { const pattern = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[0

我有一个正则表达式来检查inputText是否为有效的url格式。 而且工作几乎很好:

checkUrlFormat() {
    const pattern = /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-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,})))(?::\d{2,5})?(?:\/\S*)?$/;

    if (pattern.test(this.inputText) || this.inputText == null) {
      return false;
    }
    return true;
  }
但我需要缩短该模式,因此我在as中编写了一个regexp

((http | https)(:/)?((www.)?)[a-z0-9]+(.|[a-z0-9])+[a-z0-9]

但它是javascript格式的,我找不到如何在上面的代码中使用该字符串。当我直接复制粘贴它时,它给出了语法错误。如何组合它们。

checkUrlFormat(){
常量模式=/^((http | https)(:\/\/)?((www.))?)[a-z0-9]+(.|[a-z0-9])+[a-z0-9]$/;
if(pattern.test(this.inputText)| | this.inputText==null){
返回false;
}
返回true;

}
尝试将前向斜杠从
(:/)
转义到
(:\/\/)
,以避免语法错误。您甚至可以将其缩短为:“(http | https)”到:“https?”,就像在原始正则表达式中一样(节省一些字节)。IDN(国际域名)URL如何?