解决方案 »

  1.   

    顶一下,
    javascript:alert("thmaith thqueht myei".match(/(?!th$)\w+/))匹配的结果是thmaith
      

  2.   

    正则表达式中括号中的$是表示已什么结尾的 结束符
    (?!) 正向预搜索否定,判断当前位置右侧是否不能够匹配指定表达式
    (?!th$) 表示向后面搜索不是已th结尾的
    其实你上面的两个匹配都是错误的:
    ("thmaith thqueht myei".match(/(?!th$)\w+/)) 匹配到的是一个数组array[0]=thmaith,array[1]=thqueht,array[2]=myei
      

  3.   

    补充说明下 str.match(rge) 用正则表达式模式在字符串中运行查找,并返回包含该查找结果的一个数组(全文匹配模式g,否则只返回第一个匹配的内容) 所以你上面输入的只是数组中的第一匹配出来的结果。("thmaith thqueht myei".match(/(?!th$)\w+/g))可以匹配出所有结果
      

  4.   

    (?!th$) 表示向后面搜索不是已th结尾的
    但是javascript:alert("thmaith thqueht myei".match(/(?!th$)\w+/g))打印出来的匹配结果是thmaith thqueht myei,其中thmaith也匹配了
      

  5.   

    http://bbs.csdn.net/topics/290075564
    你去看看这个解释的挺清楚的
      

  6.   

    /(?!th$)/表示后面不接“th$”的“”,相连字符的中间部分
      

  7.   

    但是javascript:alert("thmaith thqueht myei".match(/(?!th$)\w+/g))打印出来的匹配结果是thmaith thqueht myei,其中thmaith也匹配了,现在就是不能理解(?!th$)括号中$的意思
      

  8.   

    但是javascript:alert("thmaith thqueht myei".match(/(?!th$)\w+/g))打印出来的匹配结果是thmaith thqueht myei,其中thmaith也匹配了,现在就是不能理解(?!th$)括号中$的意思/(?!th$)/匹配不以th结束的位置
    out="th".match(/(?!th$)/)             // out.index ==1