我正在使用c#開發Windows應用程序。我正在將文件(html,txt,xhtml)加載到文本框中。我想在我的文本框中測試下列情況的發生。在多行文本框中多次出現正則表達式
,(comma) with closeup text (ex. text1,text2)
.(dot) with closeup text (ex. text1.text2)
:(colon) with closeup text (ex. text1:text2)
,(comma) with closeup ' i.e (left single quotation mark)
"(doublequote) with closeup text
'(single quote) with closeup text
</i> with closeup text (ex. </i>text)
</span> with closeup text.
對於上述情況的所有情況,我想突出顯示文本框中特定的文本。我正在嘗試使用正則表達式。我將所有的情況都插入到數組列表中並逐個檢查。對於第一種情況,如果文本框中的文本與hjhdf,dfsjf類似,那麼它將顯示消息框,如果在此特定文本之前和之後有任何文本,則它將不顯示消息框。
string regexerror = wordToFind;
Regex myregex = new Regex("^[,]*[a-zA-Z]*$");
bool isexist = myregex.IsMatch(rtbFileDisplay.Text);
if (isexist)
{
MessageBox.Show("Hi");
}
您可以使用'(?<=^|>)[^><] +?(?= <| $)\ be(\ w *)s \ b'來匹配html中的文本。 – 2012-02-15 07:21:29