正则表达式不包含在引号中

时间:2014-06-29 18:50:27

标签: javascript regex

我有当前的RegEx

(["'])  \1|([-!$%^&*()_+|~=`{}\[\]:";'<>?,\w\/][ ]{2,})

我正在尝试匹配

var  a = '', b = '';
  something = '';
var something  = 'something i dont know'
    y =  'something'  ,
     1  = 2,
     a =  [
       'something',
        'a'
    ];

function some  () {    
  console.log('someFunction');
}

  function something () {  
      console.log('should allow multiple   Spaces 1!');
      console.log("should allow  multiple Spaces 1!");  
  }

我想要这样做它匹配双(或更多)空格,当它不在引号内时。

重要的是,它不要在每行的开头抱怨空格(最好也不在最后)

1 个答案:

答案 0 :(得分:2)

使用此模式:

\s{2,}(?=(?:(?:[^"]*"){2})*[^"]*$)

Demo