What Im Building:
The script archives a working directory using GIT-POSH and sends it to a Linux Apache Server using a Windows Powershell SSH Module.
For convenience, the script also needs to do reporting on existing files on the local machine as well as the Apache server.
The Problem:
This is where I need string manipulation to separate each block in the naming convention.
I was going to use underscores block_block until I realized some of the blocks contain underscores them already.
This is when I decided to encapsulate each block with brackets [block][block]
In PHP I would use preg_split to pull out each piece into an associative array.
[product][branch_name][date][time][commit_hash]
Expected Usage:
--> Get-Product $string
--> product123
--> Get-Branch $string
--> branch123
Questions I have:
- How do I
preg_splitthis string the same way using powershell and apache? - A better naming convention that supports the same operation?
PHP’s
preg_splitcan be mimicked withSystem.RegularExpressions.Split(). There are some caveats, namelySplit()will return empty strings for tokens it replaced, so some filtering is needed. Like so,Output:
Without the filtering clause
? { $_.length -gt 0 }– which will exclude string objects that have length of zero – the output would be slightly different:This behaivour is documented in MSDN.