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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.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正则表达式-每个符号,但不是XX_Javascript_Regex - Fatal编程技术网

Javascript正则表达式-每个符号,但不是XX

Javascript正则表达式-每个符号,但不是XX,javascript,regex,Javascript,Regex,我必须将字符串(用户生成的)转换为正则表达式规则 我的问题是我必须说 更换所有标志,但不要更换 a-b,0-9,负号,点和逗号 我希望有人能帮忙 HTML <div id="d1" class="line1"></div> JS $(function() { new_regex_rule = 'hello,bl.com,dkd-dkd.com,blub,blib,satssan kommt'; // new_regex_rule = new_re

我必须将字符串(用户生成的)转换为正则表达式规则

我的问题是我必须说

更换所有标志,但不要更换 a-b,0-9,负号,点和逗号

我希望有人能帮忙

HTML

<div id="d1" class="line1"></div>

JS

$(function() {

    new_regex_rule = 'hello,bl.com,dkd-dkd.com,blub,blib,satssan kommt';

    // new_regex_rule = new_regex_rule.replace(/[a-z][0-9][-.]/gi,'');

    $('#d1').append('<hr />'+new_regex_rule+'<hr />');  

    if(new_regex_rule.match(/\s/)){ new_regex_rule = new_regex_rule.replace(/\s/,'\\s'); }
    if(new_regex_rule.match(/,/)){ new_regex_rule = new_regex_rule.replace(/\,/,'|'); }

    $('#d1').append('<hr />'+new_regex_rule+'<hr />');  
});
$(函数(){
新规则=‘你好,bl.com,dkd.com,blub,blib,satsan kommt’;
//新规则=新规则。替换(/[a-z][0-9][-.]/gi');
$('#d1')。追加('
'+new_regex_rule+'
'); 如果(new_regex_rule.match(/\s/){new_regex_rule=new_regex_rule.replace(/\s/,'\\s');} if(new_regex_rule.match(/,/){new_regex_rule=new_regex_rule.replace(/\,/,'|');} $('#d1')。追加('
'+new_regex_rule+'
'); });
工作示例

提前谢谢! 彼得


编辑:或者可以将字符串作为正则表达式规则使用吗?

此字符串替换每个符号,但不替换a-b、0-9、减号、点和逗号(区分大小写)


此符号替换所有符号,但不替换a-b、0-9、减号、点和逗号(区分大小写)


无需转义字符集中的
。@Gumbo感谢您的课程。这是我的常见行为,我现在知道这已经过时了;)已修复。无需转义字符集中的
。@Gumbo感谢您的课程。这是我的常见行为,我现在知道这已经过时了;)修好了。
var regex = /[^a-z0-9.,]/g
alert("cAspar.@hotmail.com.replace?".replace(regex,"X"));