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 

stuck with regex multiple matches

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





PostPosted: Wed Jun 27, 2007 8:02 pm    Post subject: stuck with regex multiple matches Reply with quote

i want to do something that is, essentially, RegExMatchAll

i have strings of text that go something like:

text text 123-456-789 text text 123-456-789 text text 123-456-789 text

i want to extract all the number sequences.

the description of RegExMatch makes me think i can do it with something like:

Code:
regexmatch(myvar, "(\d\d\d-\d\d\d-\d\d\d)", outvar)


...which would put all the results in outvar1, outvar2....


but it doesn't work. i get the first one, but not any others.

what am i doing wrong?

jack
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Wed Jun 27, 2007 8:08 pm    Post subject: Reply with quote

i think this was answered recently, but I can't find it - it may be in this thread:
http://www.autohotkey.com/forum/topic13545.html

I seem to remember a looping having to be done.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Thu Jun 28, 2007 5:01 am    Post subject: Reply with quote

Here's an alternate suggestion, using two RegExReplace commands
Code:
outvar := RegExReplace(myvar, ".*?(\d\d\d-\d\d\d-\d\d\d)", "$1|")
outvar := RegExReplace(outvar, "(.*)\|.*$", "$1")

The result wll be all the ###-###-### paterns seperated by |s. So you can either use Loop Parse or StringSplit after that. The second RegExReplace just gets rid of the trailing | and any left over text after it.
Back to top
View user's profile Send private message
jack



Joined: 04 Sep 2004
Posts: 74
Location: UK

PostPosted: Thu Jun 28, 2007 5:17 pm    Post subject: Reply with quote

Quote:

outvar := RegExReplace(myvar, ".*?(\d\d\d-\d\d\d-\d\d\d)", "$1|")
outvar := RegExReplace(outvar, "(.*)\|.*$", "$1")



that's a neat idea. i'll give it a go.

thanks

jack
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