1
<ReportExport ID="export1" runat="server" AlertNoTests="false" PDFPageOrientation="Portrait"
            HideExcel="true" OnPDFClicked="CreatePDF" AllowPDFOptions="true" HideBulkPDFOptions="false"
            HideOrientation="true" HidePaperSize="true" MaxReportsAtOnce="250" HideTextExport="true" />

I'm trying to use Visual Studio's find feature using regular expressions to find ReportExport in my entire solution where the HideTextExport property is not being set. This is only ever defined in the markup once on a given page.

Any ideas on how I would find where ReportExport exists... but HideTextExport does not exist in the text?

Thanks in advance!

daniel
  • 155
  • 3
  • 10
  • I tried something like: ReportExport.*^(?!.*HideTextExport).*$ but, that didn't work. – daniel Mar 28 '12 at 18:09
  • possible duplicate of [Regular expression for a string containing one word but not another](http://stackoverflow.com/questions/2953039/regular-expression-for-a-string-containing-one-word-but-not-another) – Joshua Pinter Apr 08 '14 at 17:45

2 Answers2

2

This works for me:

\<ReportExport(:Wh+~(HideTextExport):w=:q)+:Wh*/\>

:Wh+ matches the whitespace preceding the attribute name and :w matches the name, but only after ~(HideTextExport) confirms that the name is not "HideTextExport". :q matches the attribute's value (assuming values are always quoted). < and > have to be escaped or VS Find will treat them as word boundaries.

This is effectively the same as the .NET regex,

<ReportExport(?:\s+(?!HideTextExport)[A-Za-z]+="[^"]+")+\s*/>
Alan Moore
  • 73,866
  • 12
  • 100
  • 156
0

First off one should install the Productivity Power tools to Visual Studio (via Tools->Extension Manager) and use .net regex instead of the antiquated regex provided out of the box for the Visual Studio Find.

With that the user could use this regex pattern (if the productivity power tools has singleline turned on to handle the span of lines for the element):

(ReportExport.+?HideTextExport="false")

That will return all reportexports where its false and one could tweak the regex to change it to replace false to true.

But...if the HideTextExport is missing, this makes regex a poor choice to use to find this element because the uncertantity of the location of the attribute makes the .* or .+ too greedy and ends reporting false positives when trying to find a missing text in a match.

A generalized way of saying that is, regex finds patterns and that is its job, but it requires lexical analsys to find missing patterns where regex simply cannot.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
  • I'm really liking Productivity Power Tools... do you happen to know where I would change the setting for singleline? – daniel Mar 28 '12 at 19:57
  • I am getting the same error as the third poster here: http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef/view/Discussions/7 Seems to be a bug with this VS Extension. – daniel Mar 28 '12 at 20:08
  • I love the tools, I have my tab well on the left side instead of the top. But I digress, I checked, there is no place to set Singleline. :-(, Note one could write a visual studio macro with a little more smarts and do what you need. – ΩmegaMan Mar 28 '12 at 20:20
  • I may have got the the normal regex to work, but it was searching for over an hour (it's a big solution)... so it may just not be practical to do what I'd like to do. I could write myself a windows app to parse the text of all the aspx.cs files in my solution if all else fails. – daniel Mar 28 '12 at 20:58