string := "this is a test" f1:: result := string ~= z traytip,, % result Return
aka
f1:: result := RegExMatch(string, z) traytip,, % result Return
Posted 28 March 2012 - 03:34 AM
string := "this is a test" f1:: result := string ~= z traytip,, % result Return
f1:: result := RegExMatch(string, z) traytip,, % result Return
Posted 28 March 2012 - 04:07 AM
Posted 28 March 2012 - 04:12 AM
Posted 28 March 2012 - 05:32 AM
Posted 28 March 2012 - 06:28 AM
f4::traytip,, % (var = "") ? ("empty") : ("not empty")Posted 28 March 2012 - 12:13 PM
MsgBox % "pos " RegExMatch("abc", "", m, 1) " len " StrLen(m)
MsgBox % "pos " RegExMatch("abc", "", m, 2) " len " StrLen(m)There are other ways that an empty string can match, such as the * and ? quantifiers. For example, "a*" will match zero or more of the character 'a'. There are also ways that a pattern can match zero characters at one position, but not another. For example, "(?=a)" matches zero characters, but only at a position where "a" matches.MsgBox % "pos " RegExMatch("abc", "a*", m) " len " StrLen(m)
MsgBox % "pos " RegExMatch("abc", "d*", m) " len " StrLen(m)
MsgBox % "pos " RegExMatch("abc", "(?=a)", m) " len " StrLen(m)
MsgBox % "pos " RegExMatch("abc", "(?=b)", m) " len " StrLen(m)The regex syntax and matching behaviour is defined by PCRE, with very little customization for AutoHotkey.Of course, you can't pass something that doesn't exist. The variable does exist, and it contains an empty string.... if you pass a nonexistent variable ...
Posted 28 March 2012 - 12:32 PM
I once saw in a book by a respected author, in which he describes a regular expression to match a number, either integer or floating point.
His regex is '-?[0-9]*\.?[0-9]*'.
However, do you think it matches in a string like 'this has no number'? Look closely. Everything is optional. Nothing is required. This regex can match all non-number examples, matching the nothingness at the beginning of the string each time.
Posted 28 March 2012 - 12:53 PM
Posted 28 March 2012 - 01:02 PM
Haystack := "ABC" Needle := "" MsgBox, % InStr(Haystack, Needle)The search starts at position 1 of Haystack. StrLen(Needle) characters (i.e. 0 characters for an empty needle) of Haystack are compared with the (0) characters in the empty Needle, so the result is "equal" and position 1 will be returned.
Posted 28 March 2012 - 10:56 PM
It's not a RegEx issue, InStr() is yielding the same result: 1.
import re var = "" test = "this is a test" result = re.match(var, test) result.start()