AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RegEx equality operator (~=) like Perl, Javascript et al.

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  

Should AutoHotkey have a RegEx-match operator?
Yes
100%
 100%  [ 15 ]
No
0%
 0%  [ 0 ]
Don't mind
0%
 0%  [ 0 ]
Total Votes : 15

Author Message
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Mon Dec 17, 2007 9:41 pm    Post subject: RegEx equality operator (~=) like Perl, Javascript et al. Reply with quote

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
View user's profile Send private message Visit poster's website
Tuncay



Joined: 07 Nov 2006
Posts: 384
Location: Berlin

PostPosted: Mon Dec 17, 2007 9:56 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Mon Dec 17, 2007 10:45 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Tue Dec 18, 2007 12:27 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Dec 18, 2007 9:38 am    Post subject: Reply with quote

Must have. Thumbs up.
_________________
Back to top
View user's profile Send private message MSN Messenger
Tuncay



Joined: 07 Nov 2006
Posts: 384
Location: Berlin

PostPosted: Tue Dec 18, 2007 9:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
tic



Joined: 22 Apr 2007
Posts: 1354

PostPosted: Wed Dec 19, 2007 8:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
AHKnow



Joined: 03 Jul 2004
Posts: 118

PostPosted: Thu Dec 20, 2007 3:15 am    Post subject: Reply with quote

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
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Thu Dec 20, 2007 12:09 pm    Post subject: Reply with quote

LOL
_________________
Back to top
View user's profile Send private message MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Thu Dec 27, 2007 3:23 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group