How to check if it contains characters other than letters, numbers and some ASCII special characters? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 616
Joined: 06 Dec 2018, 04:36

How to check if it contains characters other than letters, numbers and some ASCII special characters?

12 Feb 2020, 11:51

How to check if it contains characters other than letters, numbers and some ASCII special characters?

a-z A-Z
0-9
space!#$%&'()\+,-.:;[email protected][\]^_`{}

Such as checking if it contains :
/ * ? " < > |
Non-ASCII characters

Code: Select all

str := "a1*"

MsgBox % InStr(str, "[^ !#\$%&'\(\)\+,-\.:;[email protected]\[\\\]\^_`\{}~0-9a-zA-Z]")
What went wrong with this regular expression?
User avatar
boiler
Posts: 6601
Joined: 21 Dec 2014, 02:44

Re: How to check if it contains characters other than letters, numbers and some ASCII special characters?

12 Feb 2020, 13:11

What went wrong with your regular expression is you used InStr instead of RegExMatch.

Code: Select all

str := "a1*"

MsgBox % RegExMatch(str, "[^ !#\$%&'\(\)\+,-\.:;[email protected]\[\\\]\^_`\{}~0-9a-zA-Z]")
afe
Posts: 616
Joined: 06 Dec 2018, 04:36

Re: How to check if it contains characters other than letters, numbers and some ASCII special characters?

13 Feb 2020, 04:30

Oh, I made a stupid mistake.
However, I found that when the regular expression is written as follows, it will not match "*". Should escape sequences be followed in regular expressions as well?

Code: Select all

str := "a1*"

MsgBox % RegExMatch(str, "[^ !#\$%&'\(\)\+,-\.0-9:;[email protected]\[\\\]\^_`a-z\{}~]")

Escape Sequences
https://www.autohotkey.com/docs/commands/_EscapeChar.htm
User avatar
boiler
Posts: 6601
Joined: 21 Dec 2014, 02:44

Re: How to check if it contains characters other than letters, numbers and some ASCII special characters?  Topic is solved

13 Feb 2020, 05:03

Yes, the regular expression functions see the backtick character as an escape character. If you want to include it as a character of its own, use two in a row.
afe
Posts: 616
Joined: 06 Dec 2018, 04:36

Re: How to check if it contains characters other than letters, numbers and some ASCII special characters?

19 Feb 2020, 10:54

Thank you. You're right.

Code: Select all

MsgBox % RegExMatch(str, "[^ !#\$%&'\(\)\+,-\.0-9:;[email protected]\[\\\]\^_``a-z\{}~]")

Return to “Ask For Help”

Who is online

Users browsing this forum: Eik, kingamir022, mikeyww, teadrinker and 23 guests