Example(Not implemented at the moment):
Code: Select all
match := ("Hello123" ~= "O)\d+") ; 'O' is specified
MsgBox, % match.Pos "`n" match.Value
Code: Select all
match := ("Hello123" ~= "O)\d+") ; 'O' is specified
MsgBox, % match.Pos "`n" match.Value
Code: Select all
if (RegexMatch(Haystack, "Needle", R_)) {
DoSomethingWith(R_1)
}
Code: Select all
if (Haystack ~= "Needle") {
DoSomething()
}
Code: Select all
if (Haystack ~= "Needle", R_) {
DoSomethingWith(R_1)
}
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.Coco wrote:What would be nice is to have RegEx shorthand(~=) return an object if the O option is specified in the RegEx pattern
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:an object is treated as false in an IF statement
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.)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.
Code: Select all
:*:rem(::RegExMatch(
:*:rer(::RegExReplace(
I avoid using it because it isn't...Wade Hatler wrote:I use it because it's easier to read later.
How about(For v. 1.1+ only):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.
Code: Select all
if (var ~= "i)(red|yellow|blue)") ; if var contains
if (var ~= "i)^(red|yellow|blue)$") ; if var in
Users browsing this forum: No registered users and 28 guests