2013-12-17 20 views
-1

我在我的vb 2010應用程序中有一個文本框和一個搜索按鈕。我想獲得用戶輸入,並檢查它是否包含我列表中的任何單詞(細胞,膜,生物,動物,植物等)。請我需要正則表達式模式。VB2010正則表達式

+1

你不需要爲正則表達式。簡單的IF就足夠了。 – JohnFx

+1

人們不會在哪裏寫你的代碼。顯示你的嘗試,我們會給你建議。 –

回答

0

對於你給出的列表,你可以使用類似於下面的正則表達式:

^(cell|membrane|biology|animal|plant)$ 

要測試你的正則表達式模式,您可以前往regexpal.com

但我會建議把你所有的單詞放在一個數組中,然後進行檢查,而不是使用正則表達式,因爲它不是你匹配的模式;但針對具體的話。

1

No Regex needed,這樣做會很好。

Dim myInput as string 
myInput = myControl.value 

if (myInput="cell") or (myInput="membrane) or (myInput="biology) or... THEN 
    'do something 
End if 
1

你不需要regex來做到這一點。如果您要檢查它是否包含任何給定的話:

Dim input = "biology is good" 
Dim words = New String() { "cell", "membrane", "biology", "animal", "plant" } 
Dim contains = words.Any(Function(s) input.Contains(s))