How to find text in more than one line using Regex
-
Hi all, I am developing a CMS using asp.net 2.0 and c# 2.0. I have a html template file... with the following text in the file. {=BeginCatRecords=}
Links comes here
{=EndCatRecords=} I am reading this file in a variable let say st. Now, I want to find the text from {=BeginCatRecords=} to {=EndCatRecords=} I am using this code : string pattern = @"{=BeginCatRecords=}.*?{=EndCatRecords=}"; Match MatchTop = Regex.Match(st, pattern); string NavMatch = MatchTop.ToString(); It is working fine when I write the html in one line (as displayed above) in my html template file.. But when I change it to multiple line as : {=BeginCatRecords=}
Links comes here
{=EndCatRecords=} It doesn't work. Can you please let me know how should I change the pattern to meet the requirement.... Thank you in advance.. Suman Singh
-
Hi all, I am developing a CMS using asp.net 2.0 and c# 2.0. I have a html template file... with the following text in the file. {=BeginCatRecords=}
Links comes here
{=EndCatRecords=} I am reading this file in a variable let say st. Now, I want to find the text from {=BeginCatRecords=} to {=EndCatRecords=} I am using this code : string pattern = @"{=BeginCatRecords=}.*?{=EndCatRecords=}"; Match MatchTop = Regex.Match(st, pattern); string NavMatch = MatchTop.ToString(); It is working fine when I write the html in one line (as displayed above) in my html template file.. But when I change it to multiple line as : {=BeginCatRecords=}
Links comes here
{=EndCatRecords=} It doesn't work. Can you please let me know how should I change the pattern to meet the requirement.... Thank you in advance.. Suman Singh
There's an option you pass in to an overloaded method of the match function to make the regex run on multiple lines
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Hi all, I am developing a CMS using asp.net 2.0 and c# 2.0. I have a html template file... with the following text in the file. {=BeginCatRecords=}
Links comes here
{=EndCatRecords=} I am reading this file in a variable let say st. Now, I want to find the text from {=BeginCatRecords=} to {=EndCatRecords=} I am using this code : string pattern = @"{=BeginCatRecords=}.*?{=EndCatRecords=}"; Match MatchTop = Regex.Match(st, pattern); string NavMatch = MatchTop.ToString(); It is working fine when I write the html in one line (as displayed above) in my html template file.. But when I change it to multiple line as : {=BeginCatRecords=}
Links comes here
{=EndCatRecords=} It doesn't work. Can you please let me know how should I change the pattern to meet the requirement.... Thank you in advance.. Suman Singh
-
Many Thanks for your reply. I tried your suggestion but no avail... Here is the HTML code from a file (categories.html), I a reading in a variable st :
{=BeginCatRecords=}{=EndCatRecords=}{=CatDesc=}
In this file, from {=BeginCatRecords=} to {=EndCatRecords=} is written in one line.. and it is working fine... But if I split it in multiline like : {=BeginCatRecords=}
{=CatDesc=}
{=EndCatRecords=} It stops working... Below is the code I am using to match the string : string NavMatch = null; pattern = @"{=BeginCatRecords=}.*?{=EndCatRecords=}"; Match MatchTop = Regex.Match(st, pattern, RegexOptions.Multiline); NavMatch = MatchTop.ToString(); Please help.. Suman Singh