Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple occurrence of regular expression in a multiline textbox

Tags:

c#

regex

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");
}
like image 473
Manoj Nayak Avatar asked Feb 15 '12 04:02

Manoj Nayak


1 Answers

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.

like image 154
deadlyvices Avatar answered Oct 26 '22 03:10

deadlyvices