如何从<textarea>中删除未带括号的URL

Dav*_*ave 6 html javascript css regex jquery

附加小提琴中的代码删除了a中的所有URL <textarea>.

代码是否可以删除所有URL,除非URL在括号内 -  例如(google.com) - 在<textarea>动态内?

如果可能的话,我会欣赏一个更新的小提琴,因为我不熟悉编码.

$(function() {
  $("#txtarea").keyup(function() {
    console.log(this.value);
    this.value = this.value.replace(/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/mg, ' ');
  })
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<textarea id="txtarea" placeholder="How to stop http being entered into textarea?"></textarea>
Run Code Online (Sandbox Code Playgroud)

小提琴

Aks*_*shi 1

编辑:请对上述内容使用以下代码(包含单个 url 的字符串)。

   $(function(){
    var urlmatch = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/gm, protomatch = /\((https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\)/gm;
    $("#txtarea").keyup(function(){
        if( this.value.match(protomatch) && this.value.charAt(0) == '(' && this.value.charAt(this.value.length-1) == ')' ){
            this.value = this.value;
        }
        else if(this.value.match(urlmatch) && !this.value.match(protomatch) && this.value.charAt(0) != '(' && this.value.charAt(this.value.length-1) != ')'){
            this.value = this.value.replace(urlmatch, '');
        }
    })
});
Run Code Online (Sandbox Code Playgroud)

编辑:它将检查并删除整个字符串中所有接下来的 url(多个 url )。

       $(function(){
                $("#txtarea").keyup(function(){    
                    var urlmatch = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/, newA = [], a = this.value.split(' '); 
                $.each(a, function (i, j) {//j = $.trim(j); 
                if((j.match(urlmatch) && j.charAt(0) == '(' && j.charAt(j.length-1) == ')') != false) {
                newA.push(j)
                }
                console.log(j, '->', j.match(urlmatch) && j.charAt(0) == '(' && j.charAt(j.length-1) == ')'  ) })

                var o = newA.join(" ")
                this.value = o;
                })
            });
Run Code Online (Sandbox Code Playgroud)

找到为此更新的小提琴。干杯!