Extract string from string using Regex

Posted by stacker on Stack Overflow See other posts from Stack Overflow or by stacker
Published on 2010-05-04T17:17:06Z Indexed on 2010/05/04 17:18 UTC
Read the original article Hit count: 374

Filed under:
|

I want to extract MasterPage value directive from a view page. I want the fastest way to do that, taking into account a very big aspx pages, and a very small ones.

I think the best way is to do that with two stages:

  1. Extract the page directive section from the view (using Regex):
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
  1. Then, extract the value inside MasterPageFile attribute.

The result needs to be: ~/Views/Shared/Site.Master.

Can I have help from someone to implement this? I badly want to use only regex, but I don't Regex expert.

Another thing, Do you think that Regex is the fastest way to do this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex