回答編集履歴
1
http無しについて追記
answer
CHANGED
@@ -5,4 +5,7 @@
|
|
5
5
|
var text = '<p>あいうえおかきくけこhttp://google.com</p>';
|
6
6
|
text = text.replace(/(http(s)?://[a-zA-Z0-9-.!'()*;/?:@&=+$,%#]+)/gi, "<a href='$1' target='_blank'>$1</a>");
|
7
7
|
console.log(text);
|
8
|
-
```
|
8
|
+
```
|
9
|
+
|
10
|
+
「http」で始まらないURLについては、URLとそうでないものの判断が難しいと思います。
|
11
|
+
「google.com」をaタグに変換するなら、たとえば`text = text.replace(...`という文字列の中の「text.replace」だってaタグに変換されてしまうわけなので。
|