소스 검색

识别url 正则优化

xsx 1 년 전
부모
커밋
abdc9e5329
2개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 2 2
      im-uniapp/common/url.js
  2. 2 2
      im-web/src/api/url.js

+ 2 - 2
im-uniapp/common/url.js

@@ -1,6 +1,6 @@
 let replaceURLWithHTMLLinks = (content, color) => {
-	// 使用正则表达式匹配更广泛的URL格式
-	const urlRegex = /(?:https?:\/\/[^\s]+|www\.[^\s]+)/g;
+	// 使用正则表达式匹配更广泛的URL格式(此正则由deepseek生成)
+	const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]|\bwww\.[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
 	return content.replace(urlRegex, (url) => {
 	    // 如果URL不以http(s)://开头,则添加http://前缀
 	    if (!url.startsWith("http")) {

+ 2 - 2
im-web/src/api/url.js

@@ -1,6 +1,6 @@
 let replaceURLWithHTMLLinks = (content, color) => {
-	// 使用正则表达式匹配更广泛的URL格式
-	const urlRegex = /(?:https?:\/\/[^\s]+|www\.[^\s]+)/g;
+	// 使用正则表达式匹配更广泛的URL格式(此正则由deepseek生成)
+	const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]|\bwww\.[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
 	return content.replace(urlRegex, (url) => {
 	    // 如果URL不以http(s)://开头,则添加http://前缀
 	    if (!url.startsWith("http")) {