News for hackers. Stuff that matters.
Re:PowerShell is open sourced and is available on Linux by zamalek on Thursday August 18, 2016 @02:16PM (#12315010)
The default regex functionality is absolutely terrible (maybe this can now be fixed with a PR). You'd write your own cmdlet[1]. A few things are demonstrated in the cmdlet: functions that take pipes, functions that return pipes, anonymous functions, actions to perform before processing a pipe and dynamic objects. The Powershell syntax gets ridiculed for being ugly, but it's beautifully expressive.

> Can I take the value, convert it to string, make some magic on it and convert it to another object entirely?

    Get-ChildItem *.js | Get-Content | Select-Regex 'require\("(?<Require>.*?)"\)' | Select-Object -ExpandProperty Require
In other words: find JS files | read lines | turn regex capture groups into an object (another object entirely) | select a single capture

Ultimately, Microsoft provides WMI cmdlets[2]. You'd have strong types from the get-go and wouldn't need resort to this string silliness.

[1]: https://gist.github.com/jcdickinson/cee4582448300c0d404bbff1... [2]: https://technet.microsoft.com/en-us/library/ee176860.aspx

Re:PowerShell is open sourced and is available on Linux by jodrellblank on Friday August 19, 2016 @03:24AM (#12318450)
The default regex functionality is absolutely terrible

How so?

Re:PowerShell is open sourced and is available on Linux by zamalek on Friday August 19, 2016 @05:48AM (#12318930)
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.
Re:PowerShell is open sourced and is available on Linux by jodrellblank on Friday August 19, 2016 @04:33PM (#12323258)
I'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.