AutoHotkey Community

It is currently May 26th, 2012, 1:14 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 

Should AutoHotkey have a RegEx-match operator?
Yes
No
Don't mind
You may select 1 option

View results
Author Message
PostPosted: December 17th, 2007, 9:41 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 9:56 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2007, 10:45 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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().

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2007, 12:27 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
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)

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2007, 9:38 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Must have. Thumbs up.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 18th, 2007, 9:37 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
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%"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 19th, 2007, 8:26 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2007, 3:15 am 
Offline

Joined: July 3rd, 2004, 1:03 pm
Posts: 121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2007, 12:09 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
LOL

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 27th, 2007, 3:23 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
I never liked perl much anyway, but Ecmascript (javascript) also supports regex as objects.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group