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 

fetching spaces with RegExMatch properly

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Thu Feb 18, 2010 12:41 am    Post subject: fetching spaces with RegExMatch properly Reply with quote

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%>
)
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 3254
Location: Simi Valley, CA

PostPosted: Thu Feb 18, 2010 2:53 am    Post subject: Reply with quote

"\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!
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Thu Feb 18, 2010 3:03 am    Post subject: Reply with quote

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%>
)

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Thu Feb 18, 2010 3:31 am    Post subject: Reply with quote

I see. Thank you, [VxE] and sinkfaze!!!
My understanding of \d and \D was wrong.
Back to top
View user's profile Send private message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Thu Feb 18, 2010 4:09 am    Post subject: Reply with quote

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%>
)
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Thu Feb 18, 2010 4:21 am    Post subject: Reply with quote

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_]

_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference


Last edited by jethrow on Thu Feb 18, 2010 4:27 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Thu Feb 18, 2010 4:27 am    Post subject: Reply with quote

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.
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Thu Feb 18, 2010 4:31 am    Post subject: Reply with quote

I see. Thank you, jethrow and sinkfaze!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help 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