Which characters need to be escaped?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Which characters need to be escaped?

01 Jan 2019, 04:15

Hello,

Which characters need to be escaped? If a character is escaped in a regular expression, "\" must be used instead of "`", except for "`r", "`n"?

Thanks.
gregster
Posts: 9020
Joined: 30 Sep 2013, 06:48

Re: Which characters need to be escaped?

01 Jan 2019, 08:41

Docs say: https://www.autohotkey.com/docs/misc/Re ... ndamentals
Escaped characters: Most characters like abc123 can be used literally inside a regular expression. However, the characters \.*?+[{|()^$ must be preceded by a backslash to be seen as literal. For example, \. is a literal period and \\ is a literal backslash. Escaping can be avoided by using \Q...\E. For example: \QLiteral Text\E.
`r and `n are part of the available options, just like `a: https://www.autohotkey.com/docs/misc/Re ... tm#Options
But
Within a regular expression, special characters such as tab and newline can be escaped with either an accent (`) or a backslash (\). For example, `t is the same as \t except when the x option is used.
(https://www.autohotkey.com/docs/command ... tm#Remarks)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Which characters need to be escaped?

01 Jan 2019, 12:43

Some content from:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486

Code: Select all

;RegEx escape characters:
;12 characters that need escaping in RegEx generally: \.*?+[{|()^$
;4 characters that need escaping in a RegEx character class: ^-]\

;RegEx: note: \x22 [double quote]

;#EscapeChar - Syntax & Usage | AutoHotkey
;https://autohotkey.com/docs/commands/_EscapeChar.htm
;escape characters in AutoHotkey expressions:
;`` `a `b `f `n `r `t `v
;`; [needed when ; is preceded by a space/tab]
;"" [AHK v1]
;`" [AHK v2]
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
afe
Posts: 615
Joined: 06 Dec 2018, 04:36

Re: Which characters need to be escaped?

01 Jan 2019, 12:52

Thanks. I found that in the regular expression, the "\" must be used , of course, "\n", "\r" can be "`n", "`r", except for options. However, "`" must be used by default in general expressions.

https://www.autohotkey.com/docs/command ... peChar.htm
This document seems to be incomplete because I didn't find "}", but in fact it must also be escaped.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: NinjoOnline and 233 guests