AutoHotkey Community

It is currently May 27th, 2012, 4:15 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: February 18th, 2010, 1:41 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
Why do the spaces between a_bird and is always "creep into" the first variable res1 here:
Code:
victim=
(
a_bird        is "eagle"
)

RegExMatch(victim, "([\D|_]+)?( *)?(is)( *)?""(.*)?""", res)
msgbox,
(
res1: <%res1%>
res2: <%res2%>
res3: <%res3%>
res4: <%res4%>
res5: <%res5%>
)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 3:53 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
"\D" means any non-digit, and that includes spaces. Possibly, using a different class (like \S) or a word-boundary (\b) is appropriate in your case.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 4:03 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
I think the more important question is why shouldn't they creep into the variable? Your matching criteria for your that variable is this:

Code:
[\D|_]+


Which is one or more non-digit or underscore. A space is not an underscore but it is a non-digit, so it should match your pattern. Basically you want any alpha character or underscore here, which can be accomplished a few ways:

Code:
[\D\S_]+ ; any non-digit, non-space or underscore
[a-zA-Z_]+ ; any lowercase/uppercase alpha character or underscore
[[:alpha:]_]+ ; any lowercase/uppercase alpha character or underscore


I prefer this just for my own clarity:

Code:
victim=
(
a_bird        is "eagle"
)

RegExMatch(victim, "([[:alpha:]_]+)?( *)?(is)( *)?""(.*)?""", res)
msgbox,
(
res1: <%res1%>
res2: <%res2%>
res3: <%res3%>
res4: <%res4%>
res5: <%res5%>
)

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 4:31 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
I see. Thank you, [VxE] and sinkfaze!!!
My understanding of \d and \D was wrong.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 5:09 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
I am sorry. I tried [\D\S_] way and came across the same problem.
What am I doing wrong now? I wasn't able to find the answer on my own:
Code:
sent =
(
bird      = "eagle"
)
regexmatch(sent,"([\D\S_]+)?( *)?(=)( *)?""([\D\S_]+)?""", guf)
msgbox,
(
guf1: <%guf1%>
guf2: <%guf2%>
guf3: <%guf3%>
guf4: <%guf4%>
guf5: <%guf5%>
)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 5:21 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Code:
[\D\S_]

This will match any character that is not a digit OR not a space OR an underscore. As sinkfaze stated above, perhaps this would work better :wink: :
Code:
[a-zA-Z_]

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on February 18th, 2010, 5:27 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 5:27 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
Ignore that option I had presented, since I now realize that the matching criteria for \D and \S will apparently conflict. Try either of the other two methods instead.

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2010, 5:31 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
I see. Thank you, jethrow and sinkfaze!!!


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: rbrtryn and 65 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