Need Powershell Regex Help - Replace bound string within string

First, you can do what you've requested without a regular expression. You can use -split and -join to accomplish your purpose:

$string -split ', ' -join '-'

This returns what you requested, with one issue: it replaces the ', ' that's in the Nov 20, 10:12 PM portion of the string so you get Nov 20-10:12 PM. If you're ok with that - and I suspect you are since it seems you're trying to update CSV data for import into something else - you're good to go.

I'm assuming you're not trying to import the CSV data with Powershell because if so, you should find PS doesn't have an issue with the embedded ', ' since it recognizes double-quoted strings and won't split on the embedded commas. If you are dealing with an issue importing with PS, post more details.

/r/PowerShell Thread