.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Regex Help - Modes Multiline-Singleline

Posted By:      Posted Date: October 20, 2010    Points: 0   Category :.NET Framework

     I have a String like this

string s = @"<Body>\r\n<Font face="Arial" size=10>\r\nwelcome to Csharp Regex\r\n</Font>\r\n</Body>";

I want to Replace the string "<Font face="Arial" size=10>\r\nwelcome to Csharp Regex\r\n</Font>" to " some text";I Use the following regex.

string s = Regex.Replace(s, @"<Font (.*?)>(.*)</Font>","some Text", RegexOptions.Multiline );

It is not working properly.

How can I get this using Regex?

Please help me whether it is possible or not.

(Moderator: Thread moved to the Regular Expression Forum and title tweaked for searching purposes)

View Complete Post

More Related Resource Links

Regex pattern for validating IPv6


Can anyone can make a regular expression pattern for validating IPv6 (not IPv4)?

Ipv6 has many formats and aliases. I tried making the pattern but written in a lot of codes (i'm not sure my code below will be 100% accepting valid formats and 100% declines invalid formats).


Regex.replace [h2] to


I try to replace [h2] to <h2>
I use this coding:

string o = "<h2>test</h2>";
o = Regex.Replace(o, "[h2]", "<h2>");
o = Regex.Replace(o, "[/h2]", "</h2>");


But the result after the first regex is:


So that is not what i want.
After the first 1, he should make:


Whats wrong?

Issues with multiline textbox, javascript and IE


Hi All,

i have a requirement to embolden/italicise the selected  text in a textbox. the way it is implemented as is by using a js function which inserts <b> and </b> tags at the start and end of the selected text  for bold, and similarly <i> and </i> tags at the start and end of the selected text  for italics.

here is the code in c# (to add attributes to link buttons)

lkbBold.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'B'); return false;");
lkbItalic.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'I'); return false;");

the txtTitle is the id of the text box, which contains the selected text to be emboldend.

and here's the javascript method

function AddHTMLTags(textBoxId, format)
  var textComponent = document.getElementById(textBoxId);
  var selectedText;
  var textToReplace; 
  var content = document.getElementById(textBoxId).value;
  var content1 ;
  var content2 ;
  var newContent; 
      // For IE 
      if (document.selection != undefined)
        var len =  document.selection.createRange().text.length;
        var myrange

regex: How to allow a comma?

Hi,How to allow a comma?"^ \ $? (\ D (1.3),? (\ D (3 },?)* \ d (3) (\. \ D (0.2))? | \ D (1.3) (\. \ d (0.2))? | \. \ d (1.2 }?)$"  This is works, I need character ","Helpthanks

multi-line regex in C#

Hi, I am sure this is really simple, but i can't figure it out. I have a string that looks like this: REV=A1 STATUS=Working I would like to grab 'A1' and 'Working', in a single regex, but i cannot seem to handle the linebreak. I have tried putting something together in Rad's Regular expressions designer and this pattern will match it all: REV=(?<Rev>.{2}) STATUS=(?<Status>.+) but i don't know to write a two-lined regex in C#. I have also tried to include the linebreak, with both \n and \r, but none of them worked. So, how is my pattern suppoed to look for this?Nicolai Søndergaard LM Glasfiber A/S

I need a regex for the following sentence

I have a line of text which is as follows  : This should occur before variable1 = 1 variable2 =2 variable3=6 variable4=9   I want a regex which checks if this text (This should occur before ) comes before  the string of the variables (variable1, variable2, variable3, variable4 ) and also  should pass if the placement of the variables can occur anywhere in the sentence.Also the regex should pass only if the variable4 has a value greater than 9.  

Regex for checking number greater than 9

Hi All , I need to write a regex which can check for a number greater than equal to 9 .  

Exclude a word regex

Currently i am using one regex for accepting some records from a file.  That regex is ^[a-zA-Z0-9| ].*$. This regex accepts record starting with alphanumerics or blank space.I want to modify this regex such that, previous conditions should be there and regex should not accept record starting with word 'bbb'. Which regex should be used?

Need RegEx for four decimal place

Hello All, I have total 19 digits in which i have 4 decimal place. What would be the pattern. ThanksBizTalk Beginner

Formating Text using Regex

Hello Everyone,   I have extracted some text from HTML pages & writing it to a Text file. Text is scrambled everywhere in the file after saving.   in the output text there some new line , tabs etc ... is there any way to remove them ? using Regex ?? text i am getting after extraction :- ( checked using Debug ) Pradeep \r\n\t\t\t\t\t\t\t    \r\n\t\t\t\t\t\t      G\r\n                               \r\n                                 \r\n                                \r\n                                State College \r\n                                 \r\n 

Split string using Regex with escape sequences

What is the regex to split a string using the delimiter ';', but not split on '\;' ? Backslash would be my escape character in my split string, so finding '\;' would not split, but '\\;' would split. For example I want a regex that would split the following:     "aaa;bb;cccc\;dd\;eee\\;ff\\;ggg\\\;hhh" into the following string array:     aaa     bb     ccc\;dd\;eee\\     ff\\     ggg\\\;hhh   Thanks!   -Sylvain

Best regex for email body on contact form?

I'm not sure the best way to do a regex for the body section of an email contact form.  I want to use the regex to prevent more than 150 characters from being entered.  I assume this is sufficient, I may need more.  I also want it to help guard against sql injection attacks. The more I think about it the more characters I can think of that should be allowed.  I want to allow punctuation since it's for an email and people should be using full sentences.  These are some other things that make sense to allow: " , ', : , ; , $ , . , ! , ? , - , _ , @ , & , ( , ). They cover situations when someone may put an email address or phone number in the body section for the email.  I also want to allow letters and numbers.    I'm not sure if it's best to allow the characters I mentioned or not allow characters that pose a potential threat.  I think allowing the ones I want is the best way, but I'm not sure.  Can someone please give an example and/or suggestions?  Are there other characters that should be allowed?  I don't have much yet: "^(?i)[a-z0-9\s]{1,150}$"

Multiline Option does not work

Hi,Below is the sample piece of code(The code is in VB.NET), where I am expecting an answer of "true" with my basic knowledge of Regular Expressions.---------------------------------------------------'VB   Dim r As New Regex("^def$", RegexOptions.Multiline)   Dim d As String = String.Format("{0}{1}{2}{3}{4}{5}", "abc", System.Environment.NewLine, "def", System.Environment.NewLine, "def", System.Environment.NewLine) MsgBox(r.Match(d).Success)-----------------------------------------------------------The answer I get is false, but there are two "def" in 2nd  and 3rd line of the data and Multiline option is enabled, I have checked it with VS 2005 and VS 2008, both give me answer as false.  What is the mistake I have done? Please help.Thanks and Best Regards,Bennz Benz

REGEX does not match when line ends with the characters.. also, how to negate words that contain the

\S*(ai|ie)\S*   seems to match all words with characters ai and ie in them.  However it does not match if the line ends with them, how can fix that?Also, how can I match all words that DO NOT contain those characters.. I've tried ?! and [^ to no avail.Thanks in advance for any help or information!

How to find misspelled words with regex

Hi all I need a RegEx that will find a specific word within a long string. The issue is that this word may be misspelled and I need to find it even so. I would like to accept a certain percentage of wrong-ness when looking for the word. Ex. The complete string: Hello, this is my comp/et string to look at The word to search for: complete Let's say that I which to accept a maximum of two wrong letters in the above string, then the RegEx should match the word complete. However, if I only accept 1 wrong letter it shouldn't find it. Ideally the RegEx would also be able to handle whitespaces, and missing letters. Ex: The complete string: Hello, this is my com plee string to look at The word to search for: complete This should match the word as well, even though there is a whitespace between 'm' and 'p' and the letter 'l' is missing. Is this possible at all with RegEx or should I be looking at an alternative way to solve it? Thanks, Tommy

RegEx, XSD and Dataset not working together?

i have a XSD file that includes that includes the simple types     <xs:simpleType name="PhoneNo">         <xs:restriction base="xs:string">             <xs:pattern value="0(1|2|3|7)\d+" />             <xs:maxLength value="11" />             <xs:minLength value="10" />         </xs:restriction>     </xs:simpleType>     <xs:simpleType name="Email">         <xs:restriction base="xs:string">             <xs:pattern value=".+@.+\.\w+" />         </xs:restriction>     </xs:simpleType> and the element      <xs:element name="Input" msdata:IsDataSet="true" msdata:Locale="en-GB">         <xs:complexType>             <xs:choice minOccurs="1" maxOccur

RegEx Request - Extract an tag from string...

Hello, Can anyone give me a regular expression that will extract the <img> tag from a string.  I am receiving descriptions from an rss feed and the description contains an <img> tag in the text.  I want to extract the <img> so that I can display it in a different location on my page. I have fooled with some regular expressions, but my knowledge of them is not very good. Thanks in advance for any help!!
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend