回答編集履歴
1
コードの一部修正
test
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
<script>
|
3
3
|
window.onload=function(){
|
4
4
|
var h="https://www.sony.net/ https://teratail-v2.storage.googleapis.com/assets/img/common/ttlHeader.png?1632990234197348";
|
5
|
-
hm = h.match(/(http(s)?://[a-zA-Z0-9-.!'()*;/?:@&=+$,%#]+)/gi);
|
5
|
+
hm = h.match(/(http(s)?:[/][/][a-zA-Z0-9-.!'()*;/?:@&=+$,%#]+)/gi);
|
6
6
|
for(i=0;i<hm.length;i++){
|
7
7
|
if(hm[i].lastIndexOf('.png?')!=-1||hm[i].lastIndexOf('.jpg?')!=-1||hm[i].lastIndexOf('.jpeg?')!=-1||hm[i].lastIndexOf('.gif?')!=-1){
|
8
|
-
h=h.replace(hm[i],"<img src='"+hm[i]+"'>"
|
8
|
+
h=h.replace(hm[i],"<img src='"+hm[i]+"'>");
|
9
9
|
}
|
10
10
|
if(hm[i].lastIndexOf('.png')+4==hm[i].length||hm[i].lastIndexOf('.jpg?')+4==hm[i].length||hm[i].lastIndexOf('.jpeg?')+5==hm[i].length||hm[i].lastIndexOf('.gif?')+4==hm[i].length){
|
11
|
-
h=h.replace(hm[i],"<img src='"+hm[i]+"'>"
|
11
|
+
h=h.replace(hm[i],"<img src='"+hm[i]+"'>");
|
12
12
|
}
|
13
13
|
}
|
14
14
|
alert(h);
|