Reputation: 2390
I have a Powershell script that produces CSV. Only it double quotes double-quotes in a string, whereas every other piece of software I use (in the Unix world anyway) uses \" inside a string instead of "" to mean one double-quote.
Using Powershell regex's, how do I turn this:
"""C:\Java\jre8\bin\java"" -Djava.library.path=""C:\some\path\lib"" -classpath ""some;long;classpath"" com.foo.app.Main"
into this?
"\"C:\Java\jre8\bin\java\" -Djava.library.path=\"C:\some\path\lib\" -classpath \"some;long;classpath\" com.foo.app.Main"
I've tried using the supposed Powershell escape character (backtick), but haven't been able to get the conversion to work.
Upvotes: 2
Views: 214
Reputation:
Use a Regular Expression with a positive lookahead zerolength assertion.
$String='"""C:\Java\jre8\bin\java"" -Djava.library.path=""C:\some\path\lib"" -classpath ""some;long;classpath"" com.foo.app.Main"
$String
$String -replace '"(?="[^"])','\'
yields:
"""C:\Java\jre8\bin\java"" -Djava.library.path=""C:\some\path\lib"" -classpath ""some;long;classpath"" com.foo.app.Main"
"\"C:\Java\jre8\bin\java\" -Djava.library.path=\"C:\some\path\lib\" -classpath \"some;long;classpath\" com.foo.app.Main"
Upvotes: 1