Regex to replace double quotes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Regex to replace double quotes

04 Jun 2017, 15:53

Can anybody help with this code? Thanks.

( I've already tried some different ways of escaping, but can't figure out how to make it work)

Code: Select all

; desired result:
; "foo foo", "bar bar", "baz baz"

myVar = "foo foo, ""bar bar, ""baz baz"
myvar := RegExReplace(myVar, ", `"", "`", ")
MsgBox, %myVar%
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Regex to replace double quotes

04 Jun 2017, 16:37

Code: Select all

myVar := "foo foo, ""bar bar, ""baz baz"
myvar := RegExReplace(myVar, """", "blabla")
MsgBox % myVar

Code: Select all

myVar = "foo foo, ""bar bar, ""baz baz"
myvar := RegExReplace(myVar, """", "blabla")
MsgBox % myVar
See especially the documentation @ Variables and expressions:

Code: Select all

[in an expression](...)To include an [two] actual quote-character inside a literal string, specify two [four] consecutive quotes
yet functions parameters are evaluated as expressions.

Hope this helps.


[EDIT] both examples are intended to illustrate the difference between Myvar= vs MyVar := which one setting an expression using the colon-equal operator.
my scripts
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Re: Regex to replace double quotes

04 Jun 2017, 16:59

A_AhkUser wrote:Hope this helps.
Yes, it works, thanks.
User avatar
slyfox1186
Posts: 56
Joined: 28 Oct 2018, 23:56

Re: Regex to replace double quotes

02 Nov 2022, 07:49

Late reply but I suppose better than never.

Finds all double quotes stored in the Clipboard variable and replaces them with a single quote.
Examples:

Find: ""C:\path\to\file.txt""
Replace with: "C:\path\to\file.txt"

Find: "C:\path\to\AutoHotkey.exe" ""C:\path\to\file.txt""
Replace with: "C:\path\to\AutoHotkey.exe" "C:\path\to\file.txt"

Code: Select all

Clipboard := RegExReplace(Clipboard, "(""){2}", """")
MsgBox, % Clipboard
Return
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Regex to replace double quotes

02 Nov 2022, 09:44

Code: Select all

str      = "foo foo, ""bar bar, ""baz baz"
old      = , "
replace := """, "
out     := StrReplace(str, old, replace)
MsgBox, 64, Result, %out%

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 344 guests