On Jun 11, 12:54 pm, dm_14 <d...@xxxxxx> wrote:
> Hi
>
> I have a csv file which contains data as follows:
>
> 1/06/2008,9135947,aWER,83099264,"$1,000",3,$1.11
> 1/06/2008,$1.11,"$14,000",83099264,"$1,000",3,$1.11
>
> The following regex will capture the dollars amounts within quotes which
> have commas
> "\$[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*"
>
> Question1
> the regex finds "$1,000", "$14,000", etc what I want is to find and replace
> the commas within these results with a *. ie,
> $a = get-content c:\1.csv
> $a replace "\$[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*" , "*"
> ??
>
> Question2
> My regex has quotes (") within the expression, how do I use this in
> Powershell ?
>
> Thanks! dm_14,
I'll answer your second question first. The easiest way to use double
quotes within a string is to wrap the string in single quotes:
'look at me, I have "double quotes"!'
As for your second question, I need to be sure I understand what you
are asking for. For your example text, do you want the modified text
to look like this:
1/06/2008,9135947,aWER,83099264,"$1*000",3,$1.11
1/06/2008,$1.11,"$14*000",83099264,"$1*000",3,$1.11
If so, then this will get you there:
$a -replace '("\$[^"\\\r\n,]*),([^"\\\r\n,]*)"', '$1*$2"'
If not, I might need a little more information. Your original regular
expression will match quoted dollar amounts that don't have commas,
which, if I understand correctly, you would want to leave alone.
I hope this helps.
Jeff