mirror of
https://gitee.com/270580156/weiyu.git
synced 2026-05-18 05:08:02 +00:00
21 lines
766 B
HTML
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> |