I am developing a windows application using c#. I am loading a file (html, txt, xhtml) to the text box. I want to test the occurrence of following cases in my text box.
,(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.
For all the occurrences of the above condition I want to highlight the particular found text in the textbox. I am trying to use the regular expression. I am inserting all the cases in the array list and checking one by one. For the first case if the text in the textbox is like hjhdf, dfsjf then it will show the message box, if any text before and after this particular text then it will not show the messagebox.
string regexerror = wordToFind;
Regex myregex = new Regex("^[,]*[a-zA-Z]*$");
bool isexist = myregex.IsMatch(rtbFileDisplay.Text);
if (isexist)
{
MessageBox.Show("Hi");
}
At the moment you're only matching the beginning of the entire text with ^
. You need to get it to match the beginning of a line instead.
Look at this link: http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx. This explains use of the MultiLine property:
myregex.MultLine=true;
This should do the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With