| View previous topic :: View next topic |
| Should AutoHotkey have a RegEx-match operator? |
| Yes |
|
100% |
[ 15 ] |
| No |
|
0% |
[ 0 ] |
| Don't mind |
|
0% |
[ 0 ] |
|
| Total Votes : 15 |
|
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Mon Dec 17, 2007 9:41 pm Post subject: RegEx equality operator (~=) like Perl, Javascript et al. |
|
|
This follows on from John B.'s topic titled "Could Loop, Filepattern use regular expressions?."
We should have a new regex equality operator for string matching without calling functions, e.g.
| Code: | if (var ~= "[\d\.+\-]")
MsgBox, input cannot contain numbers
vtype := (var ~= "i)^0x[a-f\d]{1,16}$" ? "hex" : "NaN") |
The existing RegExMatch and RegExReplace functions can be left in for additional features. This will simplify many of the tasks AutoHotkey was designed for. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 384 Location: Berlin
|
Posted: Mon Dec 17, 2007 9:56 pm Post subject: |
|
|
I voted for yes, we should have.
Without calling the regexmatch function, that could speed up. Return should be just 0 or 1, like any other equality.
edit: How about ErrorLevel to use as UnquotedOutputVar? |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Mon Dec 17, 2007 10:45 pm Post subject: |
|
|
| Tuncay wrote: | | How about ErrorLevel to use as UnquotedOutputVar? | Some would argue that ErrorLevel be reserved only for commands and functions, but I wouldn't mind. I'm glad you mentioned performance, this operator could serve as a non-cached and non-capturing super fast alternative to RegExMatch(). _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Tue Dec 18, 2007 12:27 am Post subject: |
|
|
I would say it should still return FoundPos, since that matches some of the other functions in AHK. I don't think it will be bad for performance. (Kind of like WinExist actually returns a handle) _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Dec 18, 2007 9:38 am Post subject: |
|
|
Must have. Thumbs up. _________________
 |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 384 Location: Berlin
|
Posted: Tue Dec 18, 2007 9:37 pm Post subject: |
|
|
If ErrorLevel would be used, then returning FoundPos is not needed that much. But, without ErrorLevel, I am also returning for FoundPos.
| Code: | If x ~= \d\d:\d\d
MsgBox %ErrorLevel% |
How simpler could this be?
The equivalent currently is
| Code: | If RegExMatch(x, "\d\d:\d\d", OutputVar)
MsgBox "%OutputVar%" |
|
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1354
|
Posted: Wed Dec 19, 2007 8:26 pm Post subject: |
|
|
I completely agree. hadnt thought of this, but now you mention it, it seems like a great idea.
btw....
I think RegexReplace also needs to have a variable for foundpos badly! its so annoying using regexmatch as well just to tell regexreplace where to search from! |
|
| Back to top |
|
 |
AHKnow
Joined: 03 Jul 2004 Posts: 118
|
Posted: Thu Dec 20, 2007 3:15 am Post subject: |
|
|
| Great request, however Perl is probably not the best example of a language to follow. Looking at Perl for too long can cause you to go insane. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Thu Dec 20, 2007 12:09 pm Post subject: |
|
|
LOL _________________
 |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Thu Dec 27, 2007 3:23 pm Post subject: |
|
|
I never liked perl much anyway, but Ecmascript (javascript) also supports regex as objects. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
|