Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to find text in more than one line using Regex

How to find text in more than one line using Regex

Scheduled Pinned Locked Moved ASP.NET
regexcsharphtmlasp-nettutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Suman Singh
    wrote on last edited by
    #1

    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

    C E 2 Replies Last reply
    0
    • S 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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S 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

        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #3

        Have you tried: Regex.Match(string1,string2, RegexOptions.Multiline)

        S 1 Reply Last reply
        0
        • E ednrgc

          Have you tried: Regex.Match(string1,string2, RegexOptions.Multiline)

          S Offline
          S Offline
          Suman Singh
          wrote on last edited by
          #4

          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=}


          {=CatName=}

          {=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=}


          {=CatName=}

          {=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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups