Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用replace()将Wrapp链接改为强链接_Javascript_Regex_Replace - Fatal编程技术网

Javascript 用replace()将Wrapp链接改为强链接

Javascript 用replace()将Wrapp链接改为强链接,javascript,regex,replace,Javascript,Regex,Replace,我想在div中的链接周围做一个强标记。这些链接会动态显示 我试着这样做: $('#alertWrapp').each(function() { $(this).html($(this).text() .replace(/#[a-z0-1A-Z]+/g, '<span style="color: #ed6567;">$&</span>') .replace('http://', '<strong>$&</strong&g

我想在div中的链接周围做一个强标记。这些链接会动态显示

我试着这样做:

$('#alertWrapp').each(function() {
  $(this).html($(this).text()
    .replace(/#[a-z0-1A-Z]+/g, '<span style="color: #ed6567;">$&</span>')
    .replace('http://', '<strong>$&</strong>')
  );
});
$('#alertWrapp')。每个(函数(){
$(this.html($(this.text)()
.更换(/#[a-z0-1A-Z]+/g,“$&”)
.replace('http://','$&'))
);
});
但是我不能继续正则表达式,它太复杂了。。。因此,有可能构建一个regex,找到http://protocole-to-space?因为这是一个空间谁设置了我的链接结束


谢谢你

你为什么不设计一下锚呢。检查这个

如果是要用粗体包装的url文本,请尝试以下操作或选中此选项

var text=data.replace(/https?:\/\/[^]+/g,$&
要替换http://[anything until space]或https://[anything]请尝试以下操作

$('#alertWrapp').each(function() {
    $(this).html(
        $(this).text()
        .replace(/#[a-z0-1A-Z]+/g, '<span style="color: #ed6567;">$&</span>')
        .replace(/https?:\/\/[^ ]+/g, '<strong>$&</strong>')
    );
});
$('#alertWrapp')。每个(函数(){
$(this.html)(
$(this.text())
.更换(/#[a-z0-1A-Z]+/g,“$&”)
.replace(/https?:\/\/[^]+/g,$&)
);
});

为什么不应用css类呢?因为我无法控制返回给我的文本。。。事实上,文本不仅是url,也是简单的字符串和哈希标记。这就是为什么我需要用javascript替换http://to space。我想他有纯文本格式的链接,没有html标记
var text = data.replace(/https?:\/\/[^ ]+/g, '<strong>$&</strong>')
$('#alertWrapp').each(function() {
    $(this).html(
        $(this).text()
        .replace(/#[a-z0-1A-Z]+/g, '<span style="color: #ed6567;">$&</span>')
        .replace(/https?:\/\/[^ ]+/g, '<strong>$&</strong>')
    );
});