Files
weiyu/visitor/web/h5/url.html
jack ning 8a84e6b738 update
2024-04-05 15:53:09 +08:00

21 lines
766 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>正则识别url scheme</title>
</head>
<body>
hello 识别 URL
<script type="text/javascript">
function replaceUrlScheme(text) {
const urlRegex = /(\b[a-z]+:\/\/\S+)/gi;
return text.replace(urlRegex, '<a href="$1" target="_blank">$1</a>');
}
const text = '这是一个示例链接 https://www.example.com/ 和另一个链接 ftp://ftp.example.com/, 还有一个测试 thinkflow://xxx?a=b&c=d';
const result = replaceUrlScheme(text);
console.log(result);
</script>
</body>
</html>