I have an automated process for building the necessary regular expression using Emacs. It has a function called regexp-opt which builds an optimized regular expression to search for a list of words.The result is converted to a Powershell regex with a list of string replacements such as “\(” to “(” etc.
###################################################################### # # MYVARS # # Displays *ALL* Non-AUTOMATIC PS Variables in a scope range. # With the -del option it cleans up the variables in that range. # Requires Get-MaxScopeID posted by Kiron 20080917. # ###################################################################### function MyVars([int]$minScope=0, [int]$maxScope=$(Get-MaxScopeID), [switch]$del) { $ScopeLimit = (Get-MaxScopeID) if ($minScope -gt $maxScope){throw "Myvars [<min>] [<max>]"} "Maximum Scope range specification is 0..$($ScopeLimit - 1)" if ($minScope -lt 0 -or $maxScope -lt 0){throw "Scope out of range."} $maxScope++ #These offsets are to account $minScope++ #for $this scope which goes away if ($maxScope -gt $ScopeLImit){$maxScope = $ScopeLimit} if ($minScope -gt $maxScope) {$minScope = $maxScope} $minScope..$maxScope|%{Get-Variable -scope $_|Select-Object Name,Value| Add-Member noteproperty 'Scope' ($_ - 1) -passthru}| ?{$_.name -notmatch ( '^(Co(?:mmandLineParameters|n(?:(?:firmPreferenc|soleFileNam)e))|DebugPref' + 'erence|E(?:rror(?:ActionPreference|View)?|xecutionContext)|FormatEnumerat' + 'ionLimit|H(?:OME|ost)|L(?:ASTEXITCODE|oad_Library_Paths)|M(?:aximum(?:(?:' + 'Alias|Drive|Error|Function|History|Variable)Count)|yInvocation)|NestedPro' + 'mptLevel|OutputEncoding|P(?:ID|ROFILE|S(?:BoundParameters|C(?:mdlet|ultur' + 'e)|EmailServer|HOME|MaximumReceived(?:(?:DataSizePerCommand|ObjectSize)MB' + ')|Session(?:(?:Applic|Configur)ationName)|TypePath|(?:UICultur|VersionTab' + 'l)e)|WD|rogressPreference)|ReportErrorShow(?:ExceptionClass|InnerExceptio' + 'n|S(?:(?:our|tackTra)ce))|S(?:hellId|tackTrace)|VerbosePreference|W(?:SMa' + 'nMaxRedirectionCount|(?:arning|hatIf)Preference)|args|false|input|null|pa' + 'ttern|true|[$?_^])$' )}| %{Add-Member -in $_ noteproperty 'Type' $(if ($_.Value){ $_.Value.PSTypeNames[0]}else{'Null'}) -passthru}| Sort-Object -property scope,name| %{if ($del) {Remove-Variable $_.Name -scope ($_.Scope + 1) "Deleted $($_.name)"}else{$_}}| Format-Table Scope,Name,Type,Value -a } ###################################################################### # # Get-MaxScopeID # # Returns the numeric -scope value currently equivalent to 'global' # Posted by iron 20080917 on microsoft.public.windows.powershell NG # ###################################################################### function Get-MaxScopeID () { # -2 below accounts for function and foreach scopes which go away trap {return ([int]$id - 2)} foreach ($id in 0..100) { gv -s $id >$null } }