I've split your posts from
the original thread, which has been moved.
~= is something I added impulsively, to prove that it was possible (and at the time, required only a few lines of code). Aside from a mention in the changelog, it was undocumented for nearly two years. I kept it because of its low cost and because a few people were using it, but in retrospect, I regret adding it.
Note that
~= is documented as "Shorthand for RegExMatch." It is low cost because it is simply replaced with a function call, and is not handled at run-time. Differentiating between ~= and RegExMatch would increase the cost of ~= in terms of code size, if only by a small amount.
Coco wrote:What would be nice is to have RegEx shorthand(~=) return an object if the O option is specified in the RegEx pattern
That would require differentiating between ~= and RegExMatch, unless the behaviour of RegExMatch is also changed. A better idea might be simply to return an object if the O option is specified
and UnquotedOutputVar is omitted. However, the O option is currently invalid in v2 since it is the default mode.
Wade Hatler wrote:an object is treated as false in an IF statement
Your statement is false... Objects are treated as true. No object would be returned if there is no match (as with the output var currently), so boolean expressions would continue to work. What might have confused you is that if you try to treat an object as a string or number, you get an empty string. This behaviour does not apply to boolean operators or If/While/Until statements.
Wade Hatler wrote:Another alternative would be to follow the Perl convention of creating a global (or actually, a local variable with a common name) that contains the match of the most recent Regex.
I'm against that. I considered allowing
x~="(?<foo>bar)" to write into the 'foo' variable, since it would probably require only a small modification of the code used for the UnquotedOutputVar parameter. However, that would require a more complex implementation of ~=, unless the change was to also affect RegExMatch. (Edit: Also, that functionality doesn't exist in v2, which always uses the object mode.)
I typically don't use ~=, because its meaning is obscure and quite often any time saved is lost by having to convert the expression to a function call to add parameters. Instead, I use AutoHotkey as it was originally intended!
Code: Select all
:*:rem(::RegExMatch(
:*:rer(::RegExReplace(