Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 与正则表达式相关的混淆_Javascript_Regex - Fatal编程技术网

Javascript 与正则表达式相关的混淆

Javascript 与正则表达式相关的混淆,javascript,regex,Javascript,Regex,我想使用javascript中使用的正则表达式从以下字符串中提取mkghj.bmg和pp.kp avb@gh.lk mkghj.bmg ,,,,fsdsdf.fdfd pllk.kp sdfsdf.bb,,,, pp.kp 包含在、、、中的所有内容都需要忽略。可能有多个、、、实例,但它们在字符串中始终出现偶数次(也可能不出现) 而且,avb@gh.lk有一个@符号,因此需要忽略它 我想我要找的规则是——如果有点(.)向前看,向后看:- 如果圆点包含在、、、内,则忽略它 如果点前面有一个@,点和

我想使用javascript中使用的正则表达式从以下字符串中提取mkghj.bmgpp.kp

avb@gh.lk mkghj.bmg ,,,,fsdsdf.fdfd pllk.kp sdfsdf.bb,,,, pp.kp
包含在、、、中的所有内容都需要忽略。可能有多个、、、实例,但它们在字符串中始终出现偶数次(也可能不出现)

而且,avb@gh.lk有一个@符号,因此需要忽略它

我想我要找的规则是——如果有点(.)向前看,向后看:-

  • 如果圆点包含在、、、内,则忽略它
  • 如果点前面有一个@,点和@之间没有空格,请忽略它
  • 在所有其他情况下,在点的两侧捕获一组完整的字符(直到遇到空格)
  • 我提出了这个正则表达式,但它没有帮助

    [^\, ]+([^@ \,]+\w+)[^\, ]+
    
    描述
    您可以将
    、、
    之间的字符串替换为“”,然后从剩余字符串中拆分并搜索
    @
    签名和筛选

    let str=`avb@gh.lkmkghj.bmg,,,,fsdsdf.fdfd pllk.kp sdfsdf.bb,,,pp.kp`
    让op=str.replace(/,,*?,,|/g.).split('').filter(e=>!e.includes('@')&&e);
    
    console.log(op)
    一般来说(注意捕获组):


    对于您的特定示例,这可能是

    ,,,,.*?,,,,|\S+@\S+|(\S+)
    
    您需要检查组1是否存在,请参阅。
    JS
    中,这将是:

    var myString=”avb@gh.lkmkghj.bmg,,,,,fsdsdf.fdfd pllk.kp sdfsdf.bb,,,,pp.kp“;
    var myRegexp=/,,,,,,,|\S+@\S+|(\S+)/g;
    match=myRegexp.exec(myString);
    while(匹配!=null){
    if(typeof(匹配[1])!=“未定义”){
    console.log(匹配[1]);
    }
    match=myRegexp.exec(myString);
    
    }
    您选择这两个值的规则是什么?您能谈谈选择这些字符串的一些基本原理吗?为什么您不想选择与所需字符串相似的
    pllk.kp
    ?因为pllk.kp包含在、、、中,您只需执行
    \b(mkghj.bmg)|(pp.kp)\b
    该示例仅用于说明,我想买一些一般的东西,你能帮我查一下吗?我想买4组matches@vjjj我想你忘了按第一行末尾的enter键,这样它就可以正确地匹配这两行。我会在你的正则表达式中做一个小小的更改:,,,,,|\S+@\S+|(\S+\.\S+@vjj:去做:-)
    ^ asserts position at start of a line
        Match a single character not present in the list below [^ ]+
        + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
          matches the character   literally (case sensitive)
          matches the character   literally (case sensitive)
        1st Capturing Group ([^ ]+)
            Match a single character not present in the list below [^ ]+
            + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
              matches the character   literally (case sensitive)
         ,,,, matches the characters  ,,,, literally (case sensitive)
        .* matches any character (except for line terminators)
            * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
        ,,,, matches the characters ,,,, literally (case sensitive)
        \s+ matches any whitespace character (equal to [\r\n\t\f\v ])
            + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
        2nd Capturing Group (.*)
            .* matches any character (except for line terminators)
    
    not_this | neither_this_nor_this | (but_this_interesting_stuff)
    
    ,,,,.*?,,,,|\S+@\S+|(\S+)