AspAdvice.comAspAdvice.comSqlAdvice.comXmlAdvice.comRegExAdvice.com


  Viewing Message # 281032
List: regex@aspadvice.com
Date/Time: 5/11/2010 8:04:00 AM
Subject: Need help ending at double quote
Posted By: Todd Davis <toddhd@gma
Body: I am trying to parse a Visual Studio project file, and pull out all the
*.xaml pages that marked as Page Include. To be more specific, I want to get
the value of whatever is between the double quotes. Here is a partial
example:

<Page Include="Error.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:MarkupCompilePass1</Generator>
</Page>
<Page Include="MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:MarkupCompilePass1</Generator>
</Page>
<Page Include="Properties\DesignTimeResources.xaml"
Condition="'$(DesignTime)'=='true' OR ('$(SolutionPath)'!='' AND
Exists('$(SolutionPath)') AND '$(BuildingInsideVisualStudio)'!='true' AND
'$(BuildingInsideExpressionBlend)'!='true')">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<ContainsDesignTimeResources>true</ContainsDesignTimeResources>
</Page>

So in this case, I want to return:

Error.xaml
MainPage.xaml
Properties\DesignTimeResources.xaml

I wrote a Regex that looks this:

Regex regex = new Regex("(Page Include=\"(?<Value>.*)\")");

This works great on most of the file, and it returns the first two files as
expected. But when it gets to that third one, it fails, and return the whole
darn thing up tot he last double parens:

Properties\DesignTimeResources.xaml" Condition="'$(DesignTime)'=='true' OR
('$(SolutionPath)'!='' AND Exists('$(SolutionPath)') AND
'$(BuildingInsideVisualStudio)'!='true' AND
'$(BuildingInsideExpressionBlend)'!='true')

I found that if I alter it slightly, then I can get everything I want...

Regex regex = new Regex("(Page
Include=\"(?<Value>.*).xaml\")");

But this of course stops it from returning the .xaml portion of the value.
Not the end of the world, but I'm not learning anything here either.

Can anyone help me understand why the regex is failing on that third
Include, and how do I fix it?


-Todd Davis
www.SeaburyDesign.com



Need SQL Advice? http://sqladvice.com
Need RegEx Advice? http://regexadvice.com
Need XML Advice? http://xmladvice.com

 

Need Help? | About AspAdvice.com | Privacy Policy | Copyright

 

 

Total Users
  77939

Total Lists
68 

Total Messages Last Thirty Days
174