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. General Programming
  3. .NET (Core and Framework)
  4. Parsing ASP pages with Regex object

Parsing ASP pages with Regex object

Scheduled Pinned Locked Moved .NET (Core and Framework)
regexdatabasecomjsonhelp
1 Posts 1 Posters 1 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.
  • F Offline
    F Offline
    Frank Liao
    wrote on last edited by
    #1

    Can anyone tell me what am I doing wrong with the code on the bottom. The coee on the bottom is code that I wrote into a function that tries to correct URLs with a constant variable so that the pages could be reused for other sites. Though, at some point, it seems to have a hard time detecting one section of code where <% starts on one line and %> ends on another. I can only wonder if I'm using the wrong pattern to detect it, but test cases where I filled a bunch of \r\n in the middle shows me it works. So, somehow, the pattern is not finding the VBScript section of the file correctly. If anyone can help, please answer. All suggestions and advice are welcomed. Regex reDB = new Regex("<%[^(%>)]*%>"); Match match = reDB.Match(FileContent); int initialText = 0; StringBuilder builder = new StringBuilder(); while (match.Success) { // Now, scan inside ASP code to see if http is present. string ActivePart = match.Value; // Now, in the active part, try to find http or https. We know that // it's under quotations at this point Regex reURL = new Regex("(http\\:\\/\\/)*(https\\:\\/\\/)*www.company.com"); MatchCollection URLs = reURL.Matches(ActivePart); for(int j = 0; j < URLs.Count; j++) { builder.Append(FileContent.Substring(initialText, match.Index - initialText)); if( URLs[j].Value.IndexOf("https") == 0) { builder.Append("\" + BASESECUREURL + \""); } else { builder.Append("\" + BASEURL + \""); } initialText = URLs[j].Index + URLs[j].Length; } match = match.NextMatch(); } builder.Append(FileContent.Substring(initialText)); return builder.ToString(); NOTE: if you see a wink smiley, replace it close paren character. I can't seem to turn that smiley off to make the code look right. Frank http://www.frankliao.com

    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