2011-07-10 103 views

回答

5

如果您還需要其他與​​啓動「任何」,你可以使用負前瞻

^(?!any$).*$ 

這除了會匹配任何「字任何」。

1

事情是這樣的:

/(any)(.+)/i 
+0

這隻匹配以「any」開頭的單詞至少包含4個字符。它不會匹配「blahblahblah」。 OP是否改變了你的問題? –

1
any.+ 

..和一些文字,使30char門檻

+0

這隻會匹配以「any」開頭的單詞至少包含4個字符。它不會匹配「blahblahblah」 –

+0

哈哈匹配「blahblah」是不是一個要求,當我回答:)查看編輯歷史 – gordy

+0

道歉,@Gordy。 –

1

在JavaScript中爲此使用string.match(regexp)方法。請參見下面的代碼:

<script type="text/javascript"> 
     var str="source string contains YourWord"; 
     var patt1=/YourWord/gi; // replace YourWord within this regex with the word you want to check. 
     if(str.match(patt1)) 
     { 
     //This means there is "YourWord" in the source string str. Do the required logic accordingly. 
     } 
     else 
     { 
      // no match 
     } 
</script> 

希望這有助於...

2

這可能是更有效的方法不是使用正則表達式,這個作品,以及:

def noAny(i): 
    i = i.lower().replace('any', '') 
    return len(i) > 0 
+0

+1。但效率不是選擇一種方法的有效標準。正則表達式對於絕大多數使用它們的用途足夠快。 –

相關問題