Regular Expression Help!

  • Thread starter Thread starter osh
  • Start date Start date
O

osh

Help!

I am trying to set up a content editor. When the content editor pulls
in the page it still has the:

<%@ Page Language="C#" MasterPageFile="~/site/Interior.master" %>

line at the top of the page in the source code. I don't want the client
to be able to hit the "View Source" button in the content editor and
mess with that line of code, however, I want to keep the "View Source"
button in the editor.

I need to extract this line from the page and store it in the string.
The problem is that "MasterPageFile="~/site/Interior.master" or
"MasterPageFile="~/site/AnotherMaster.master" so I can't just do a
replace for this string because it may differ from page to page.

I am trying to use a regular expression to match <%@ Page Language="C#"
MasterPageFile="~/ because that will always be the constant. How
can I extract this from the string that holds the content of the page
and store this in a string?

Any help anyone can give would be greatly appreciated!
 
Maybe I don't understand your question fully, but I don't know why you need
to use a regex for this.

Why not just find the substring ("MasterPageFile=") which denotes the
beginning of the file master page name. Everything in between the quotes
(after the equal sign) is what you are looking for. Then it's just a simple
parsing problem.

My 2 cents,
curt
 
Reading back over my question, I am confused.

Maybe this helps.

strContent = a specified .ASPX page
strHeader = needs to contain the whole <%@ Page .... %> line

The problem is that the specified MasterPageFile in that line will
differ from page to page. I dont necessarily need what is in between
the quotes, rather the entire line no matter what the
MasterPageFile="..." points to.

Hope that makes more sense. Thanks for your help.
 
Oh... strContent has been filled from a StreamReader object... so if
you were to response.write(strContent) you would get the contents of
the ASPX page...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top