Multiple regexp appearance in multiline text box

I am developing a Windows application using C #. I am loading a file (html, txt, xhtml) in a text box. I want to check the appearance of the following cases in a 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 ' ie (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 occurrences of the above condition, I want to highlight the specific text found in the text box. I am trying to use regex. I insert all cases into the list of arrays and check one by one. In the first case, if the text in the text field is similar to hjhdf, dfsjf, then it will display a message box, if there is any text before and after this specific text, then it will not display a message.

 string regexerror = wordToFind; Regex myregex = new Regex("^[,]*[a-zA-Z]*$"); bool isexist = myregex.IsMatch(rtbFileDisplay.Text); if (isexist) { MessageBox.Show("Hi"); } 
+6
source share
1 answer

At the moment, you are only matching the beginning of the whole text with ^ . You need to get it so that it matches the beginning of the line.

Have a look at this link: http://msdn.microsoft.com/en-us/library/yd1hzczs.aspx . This explains the use of the MultiLine property:

 myregex.MultLine=true; 

That should do the job.

+2
source

Source: https://habr.com/ru/post/908488/


All Articles