5 ms·
Replicate the above without using [Regex]:: (i.e. use -matches and $matches). It forces you to radically depart from a typical Powershell mindset and approach.
by zamalek 10y ago
Replicate the above without using [Regex]:: (i.e. use -matches and $matches). It forces you to radically depart from a typical Powershell mindset and approach.
- jodrellblank 10y agoI'm not certain what you're getting at; -match doesn't handle multiple matches so you can't replicate the above just with it? Yes, that's a bit annoying. You could match line by line: gci *.js | foreach { gc $_ | foreach { if ($_ -match ..) { $Matches... which is ugly, but doesn't use [regex]::Matches. But you can do: sls 'require\("(.*?)"\)' *.js | select { $_.Matches.groups[1] } or other variants of Select-String, depending on exactly what data you want, without departing into the .Net Framework too far.