JavaScript RegExp [^abc] 表达式


定义和用法

[^abc] 表达式用于查找任何不在方括号之间的字符。

方括号内的字符可以是任何字符或字符范围。

语法
  1. new RegExp("[^xyz]")

直接量语法:

  1. /[^xyz]/

浏览器支持

所有主流浏览器都支持 [^abc] 表达式。


实例

对不在字符范围 [a-h] 内的字符进行全局搜索:

  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. var str="Is this all there is?";
  5. var patt1=/[^a-h]/g;
  6. document.write(str.match(patt1));
  7. </script>
  8. </body>
  9. </html>

结果是:

  1. I,s, ,t,i,s, ,l,l, ,t,r, ,i,s,?

分类导航