1

I want to find all the string (within the double quote) from all the .cs class files except from the comments (double slash). This is what i have came up so far, and it doesn't ignore the comments line, and it doesn't just return the string itself (content within the double quote). Can someone please help me improve this Powershell script? Thank you. I am running Win7

gci -path C:\Working\MyFolder -Include *.cs -Exclude *Designer.cs, *AssemblyInfo.cs -Recurse |
select-string -pattern '\"[^\"]*\"'  | export-csv oput.csv
Bryan Fok
  • 3,277
  • 2
  • 31
  • 59
  • 1
    It looks like you're trying to extract all strings from your sources. Note that it isn't that easy (multiline, verbatim strings, "strings" in comments, etc.). You might want to checkout [this](http://stackoverflow.com/q/965667/21567). – Christian.K Jun 06 '14 at 06:26

1 Answers1

1

can you try this :

select-string -pattern '(?<!([/]{2}.*))\".*\"'

using Positive and Negative Lookbehind it can be translate like this :

\".*\" looks for any character between double quotes

(?<!([/]{2}.*)) put before means : not preceded by [/]{2}.* (two / followed by any characters)

If you want to retreive the strings themselves :

gci -path C:\Working\MyFolder -Include *.cs -Exclude *Designer.cs, *AssemblyInfo.cs -Recurse |get-content | % {if ($_ -match '(?<!([/]{2}.*))\"(.*)\"'){$matches[0]}}
JPBlanc
  • 70,406
  • 17
  • 130
  • 175