| View previous topic :: View next topic |
| Author |
Message |
Benny-D
Joined: 29 Feb 2008 Posts: 865
|
Posted: Thu Feb 18, 2010 12:41 am Post subject: fetching spaces with RegExMatch properly |
|
|
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 |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Thu Feb 18, 2010 2:53 am Post subject: |
|
|
"\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 |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Thu Feb 18, 2010 3:03 am Post subject: |
|
|
I think the more important question is why shouldn't they creep into the variable? Your matching criteria for your that variable is this:
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 |
|
 |
Benny-D
Joined: 29 Feb 2008 Posts: 865
|
Posted: Thu Feb 18, 2010 3:31 am Post subject: |
|
|
I see. Thank you, [VxE] and sinkfaze!!!
My understanding of \d and \D was wrong. |
|
| Back to top |
|
 |
Benny-D
Joined: 29 Feb 2008 Posts: 865
|
Posted: Thu Feb 18, 2010 4:09 am Post subject: |
|
|
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 |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Thu Feb 18, 2010 4:21 am Post subject: |
|
|
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 : _________________
- 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 |
|
 |
sinkfaze
Joined: 18 Mar 2008 Posts: 5043 Location: the tunnel(?=light)
|
Posted: Thu Feb 18, 2010 4:27 am Post subject: |
|
|
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 |
|
 |
Benny-D
Joined: 29 Feb 2008 Posts: 865
|
Posted: Thu Feb 18, 2010 4:31 am Post subject: |
|
|
| I see. Thank you, jethrow and sinkfaze!!! |
|
| Back to top |
|
 |
|