| View previous topic :: View next topic |
| Author |
Message |
jack99999 Guest
|
Posted: Wed Jun 27, 2007 8:02 pm Post subject: stuck with regex multiple matches |
|
|
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
|
|
| Back to top |
|
 |
ManaUser
Joined: 24 May 2007 Posts: 1121
|
Posted: Thu Jun 28, 2007 5:01 am Post subject: |
|
|
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 |
|
 |
jack
Joined: 04 Sep 2004 Posts: 74 Location: UK
|
Posted: Thu Jun 28, 2007 5:17 pm Post subject: |
|
|
| 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 |
|
 |
|