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 

RegExMatch question - can't get 3rd value seperated

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
debstai



Joined: 09 Nov 2007
Posts: 2

PostPosted: Fri Nov 09, 2007 11:10 pm    Post subject: RegExMatch question - can't get 3rd value seperated Reply with quote

I am trying to use the RegExMatch to separate a string from a .tmp file that gets created.

Example of .tmp file

12345 John Jay Stadium UNITED STATES

I want 3 different results when it is all said and done. The United States portion was a new value added to the .tmp directory

My current RegExMatch is as follows:

position := RegExMatch(A_LoopField,"\s*(\d+)\s((\w*\s*)*)" ,result)

What I want to see is:
number=12345
name=John Jay Stadium
country=UNITED STATES

What do I need to add or change to my current RegExMatch to get UNITED STATES as a separate value.

Note: number, name and country will be different each time because it picks up the new info from each laptop. country will always be in uppercase.

Thank you
Back to top
View user's profile Send private message
fade2gray



Joined: 21 Oct 2006
Posts: 12

PostPosted: Sun Nov 11, 2007 4:24 pm    Post subject: Reply with quote

If you could separate the number, name and country elements with an infrequently used character rather than a space i.e. using a "¦" broken bar to produce "12345¦John Jay Stadium¦UNITED STATES", the following might work for you:-

Code:
\s*(\d+)*¦([\w\s]+)*¦([A-Z\s]+)*
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Mon Nov 12, 2007 2:51 am    Post subject: Reply with quote

Use the un-greedy (?) modifier and an end-of-string anchor ($).
Code:
\s*(\d+)\s([\w\s]*?)\s*([A-Z\s]*)$
(Without the anchor $, the A-Z pattern matches the 'J' in "John" and discards the rest of the string.)
Back to top
View user's profile Send private message
Guest






PostPosted: Tue Nov 13, 2007 4:34 pm    Post subject: Reply with quote

hi fade2gray,

thank you for your post, but unfortunately there is no way to display the | in the .tmp file because it is being pulled from a SQL window. there is actually a lot of space between name and country when it appears in the .tmp file.


hi lexikos,

thank you for your post.

i tried your code and it almost works. what it does is it displays it as such:

number=12345
name=John Jay Stadium United States
country=

with a lot of space between John Jay Stadium and United States.
for some reason it just does not want to separate. any ideas?
Back to top
debstai



Joined: 09 Nov 2007
Posts: 2

PostPosted: Tue Nov 13, 2007 4:39 pm    Post subject: Reply with quote

Nevermind user error...thanks lexicos that worked! I forgot the ? after the second string. you guys are good.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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