| View previous topic :: View next topic |
| Author |
Message |
debstai
Joined: 09 Nov 2007 Posts: 2
|
Posted: Fri Nov 09, 2007 11:10 pm Post subject: RegExMatch question - can't get 3rd value seperated |
|
|
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 |
|
 |
fade2gray
Joined: 21 Oct 2006 Posts: 12
|
Posted: Sun Nov 11, 2007 4:24 pm Post subject: |
|
|
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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Mon Nov 12, 2007 2:51 am Post subject: |
|
|
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 |
|
 |
Guest
|
Posted: Tue Nov 13, 2007 4:34 pm Post subject: |
|
|
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
|
Posted: Tue Nov 13, 2007 4:39 pm Post subject: |
|
|
| Nevermind user error...thanks lexicos that worked! I forgot the ? after the second string. you guys are good. |
|
| Back to top |
|
 |
|