teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

質問変更

2018/02/28 09:54

投稿

Sfidante
Sfidante

スコア90

title CHANGED
File without changes
body CHANGED
@@ -14,13 +14,11 @@
14
14
 
15
15
  それをjQuery(もしくはJavaScript)で行いたいです。
16
16
 
17
- 現状は`sample.com`という文字列があれば、そのテキスト中の全体を対象にリンク化してしまいます。
17
+ 現状はテキスト中のhttpやhttpsで始まる文字列を対象にリンク化してしまいます。
18
18
  ```jQuery
19
19
  $(".text_of_link").each(function(){
20
20
  //http、httpsなどで始まる文字列を正規表現でリンクに置換する
21
- if($(this).html().match(/sample.com/)){
22
- $(this).html( $(this).html().replace(/((http|https)://[\w?=&./-;#~%-]+(?![\w\s?&./;#~%"=-]*>))/g, '<a href="$1">$1</a> ') );
21
+ $(this).html( $(this).html().replace(/((http|https)://[\w?=&./-;#~%-]+(?![\w\s?&./;#~%"=-]*>))/g, '<a href="$1">$1</a> ') );
23
- }
24
22
  });
25
23
  ```
26
24