我需要将php正则表达式转换为Node.js。我的PHP正则表达式代码:第一个月我是Nodejs的新手。我如何转换这个?
piok6c0g1#
下面是等效的Node.js正则表达式
/\bhttps?:\/\/[^,\s()<>]+(?:\([\w\d]+\)|([^,\p{P}\s]|\/))/gu
字符串
演示和说明:https://regex101.com/r/Y2vlwe/1
5lhxktic2#
const regex = /\bhttps?:\/\/[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|\/))/g; const script = "Your input here"; const matches = script.match(regex); console.log(matches);
7vhp5slm3#
const regex = /\bhttps?:\/\/[^,\s()<>]+(?:\([\w\d]+\)|([^,\p{P}\s]|\/))/gu; const v = "https://www.google.com"; const v1 = "sampel text"; const matches = v.match(regex); // matches const matches1 = v1.match(regex); // Not matches console.log(matches); console.log(matches1);
gk7wooem4#
我假设你正在尝试检查一个有效的URL。JavaScript中最简单的事情就是这样做:
let url = 'https://gooogle.com'; try { const parts = new URL(url); console.log(parts); } catch(err) { console.error('not a valid url', err); }
4条答案
按热度按时间piok6c0g1#
下面是等效的Node.js正则表达式
字符串
演示和说明:https://regex101.com/r/Y2vlwe/1
5lhxktic2#
字符串
7vhp5slm3#
字符串
gk7wooem4#
我假设你正在尝试检查一个有效的URL。JavaScript中最简单的事情就是这样做:
字符串