AutoHotkey Community

It is currently May 26th, 2012, 5:45 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: April 26th, 2009, 12:34 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5479
Location: the tunnel(?=light)
rulfzid wrote:
@Sinkfaze

I wonder what causes the differences in performance between your regex and mine. I'd guess it's using the named subpatterns?


My guess is it's your look-ahead assertions since they don't consume any characters. I've been trying to find a good way to approach using those in my tutorial but I haven't come up with a good enough example.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 12:35 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5479
Location: the tunnel(?=light)
@ Sean

Code:
RegExMatch(Folder,"^.*\\(?=[^\\]+\\?$)",Root)


D'OH! How did I miss an answer that easy?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 12:36 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Sean wrote:
In this case, RegEx is not that un-intuitive, really verbatim to what we actually carried out.
Code:
Folder := "C:\FolderA\FolderB\FolderC"
;Folder := "C:\FolderA\FolderB\FolderC"
RegExMatch(Folder,"^.*\\(?=[^\\]+\\?$)",Root)
MsgBox % Root

See what I mean, yal are in a different league... that RegEx makes no sense to me, but it works - somehow :shock:

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 12:49 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
animeaime wrote:
See what I mean, yal are in a different league... that RegEx makes no sense to me, but it works - somehow :shock:
You just don't know yet some notations/conventions in RegEx. I just translated into RegEx what I would actually do without considering any performance.
Code:
"C:\FolderA\FolderB\FolderC\"
RegExMatch(Folder,"^.*\\(?=[^\\]+\\?$)",Root)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 12:51 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
OK, after reviewing it, I think I get it. I modified it slightly because I don't want to backtrace to a root folder - thanks.

Code:
; Folder := "C:\FolderA\FolderB\FolderC"
Folder := "\FolderA\FolderB\FolderC\"
Folder := "C:\FolderA\"
Folder := "\FolderA"

if RegExMatch(Folder,"i)(?:[A-Z]:)?\\.*\\(?=[^\\]+\\?$)",Root)
    MsgBox % Root

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 1:10 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5479
Location: the tunnel(?=light)
animeaime wrote:
See what I mean, yal are in a different league... that RegEx makes no sense to me, but it works - somehow :shock:


Not to be a shameless self-promoter (but I will), you can always check out my beginner's RegEx tutorial for AHK, it'll get you into the basics of RegEx with some slightly more advanced techniques along the way. :wink: But I'll give you a freebie on this one since Sean's answer fascinates me in its simplicity that completely eluded me:

Code:
^.*\\


The circumflex (^) is a start anchor, meaning that any matching pattern must start with whatever comes after it. In this case, the start anchor says that any matching pattern must start with zero or more of (almost) any characters (.*) followed by a literal backslash (\\).

Code:
(?=[^\\]+\\?$)


Anytime you see (?=...) in use that is a positive look-ahead assertion, meaning anything contained within the parenthesis must exist within the pattern in order to be a match. In this case the pattern that must exist is this:

Code:
[^\\]+\\?$


Where \\ is a literal dash and the circumflex is usually a RegEx start anchor, putting them together in the character class brackets like this ([^\\]) means any character that is NOT a literal dash, and the plus directly after it means that it will match one or more characters that is not a literal dash.

That pattern is followed by a literal dash, so now we're looking for one or more characters that is not a literal dash, followed by a literal dash.

The question mark means that the preceding character is optional, so now we're looking for one or more characters that is not a literal dash optionally followed by a literal dash.

The dollar sign ($) is an end anchor, meaning that any matching pattern must end with whatever precedes it. So now our positive look-ahead assertion says that we're looking for a pattern that will end with one or more characters that is not a literal dash, optionally followed by a literal dash.

The significance of the positive look-ahead assertion as opposed to a method like I used has to do with character consumption, which we won't go into here.

So the whole thing:

Code:
^.*\\(?=[^\\]+\\?$)


We're looking for a pattern that starts with zero or more of (almost) any characters followed by a literal dash and ends with one or more characters that are not a literal dash, optionally followed by a literal dash.

Hopefully that makes sense.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 1:14 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Thanks for the quick tutorial.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 2:03 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5479
Location: the tunnel(?=light)
animeaime wrote:
Thanks for the quick tutorial.


Shoot, that's the easy stuff. I've had your OOP files for weeks now and still haven't wrapped my head around the implications of what I'm looking at. :)

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 2:10 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
Feel free to ask questions on the Class library (OOP) - Help Thread. I'm trying to update the docs, but I keep getting distracted - I hate writing docs. Writing code is easy, docs, not so much.

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 7:50 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
animeaime wrote:
what's the difference between using a DllCall and simply removing the backslash?


I said "I would do it like" - only because it was shorter. :)
SubStr+StringTrimRight should be faster.

PhiLho once suggested me a simple RegEx: RegExReplace( Folder, "\\$")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, Bing [Bot], BrandonHotkey, G. Sperotto, gamax92, Google Feedfetcher, Miguel, notsoobvious, rbrtryn and 73 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