Last post Oct 24, 2016 12:36 AM by Deepak Panchal
Oct 21, 2016 09:27 AM|mark-1961|LINK
I am not overly familiar with regex and have the following scenario to cater for...
I need to identify a text phrase which can have optional break tags around it... so i want to remove instances of-
<br>My line of text.<br>
My line of text.<br>
My line of text.
How do i use regex to identify these variations?
I tried a basic ^My line of text$ regex but this didnt remove the phrase from the paragragh...
any help appreciated
Oct 21, 2016 03:08 PM|codemovement.pk|LINK
^ is the start of the string and $ is the end of the string, none of your example start nor end with My line of text.
I hope you got it.
Oct 21, 2016 03:09 PM|codemovement.pk|LINK
The question is very unclear about exactly what you're trying to accomplish. Are you trying to remove the breaks, identify that they're there, remove anything other than the breaks, something else?
Oct 24, 2016 12:36 AM|Deepak Panchal|LINK
Hi Mark ,
from the description of the thread it looks like you want to remove "<BR>" from the string.
you can use the code mentioned below.
protected void Button1_Click(object sender, EventArgs e)
string pattern = @"<br>";
string input = "<br>My line of text.<br>";
string replacement = " ";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
TextBox1.Text = result;
you will get output like mentioned below.