| View previous topic :: View next topic |
| Author |
Message |
kiu
Joined: 18 Dec 2005 Posts: 229 Location: Italy - Galatro(RC)
|
Posted: Fri Feb 15, 2008 6:38 pm Post subject: Regular expression match and output array |
|
|
I want to store in com1 the value 12 and in com2 the value 13
Why Is not correct?
| Code: | string=a12ba13b
RegExMatch(string, ".*(?:a(.*)b).*", com)
msgbox, 1:%com1%`n2:%com2% |
gives 13 only
this
| Code: | | RegExMatch(string, "(?:a(.*?)b)", com) |
gives 12 only _________________ ____________________
______________________
kiu |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Fri Feb 15, 2008 7:05 pm Post subject: |
|
|
| Code: | string = a12ba13b
RegExMatch(string, "(\d+)\D+(\d+)", com)
MsgBox, 1: %com1%`n2: %com2%
; OR you may prefer the following:
grep(string, "\d+", com_grep) ; see http://www.autohotkey.com/forum/topic16164.html
StringSplit, com_grep, com_grep, % Chr(4)
MsgBox, 1: %com_grep1%`n2: %com_grep2% |
Thanks Skan for showing me this thread. _________________
 |
|
| Back to top |
|
 |
kiu
Joined: 18 Dec 2005 Posts: 229 Location: Italy - Galatro(RC)
|
Posted: Fri Feb 15, 2008 7:13 pm Post subject: |
|
|
thanks titan, but my problem is more generic and the code above was more specific, sorry
I mean to get, for example, 12 in com1 and anything <b>here</b> in com2 for
| Code: | | string=<a>12</a><a>anything <b>here</b></a> |
or 1,2,3 in com1,com2,com3 respectively in
| Code: | | string=<a>1</a><a>2</a><a>3</a> |
_________________ ____________________
______________________
kiu |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Fri Feb 15, 2008 7:22 pm Post subject: |
|
|
Don't worry, I had suspected as much. That's why I gave sample code for the grep method - check it out. _________________
 |
|
| Back to top |
|
 |
kiu
Joined: 18 Dec 2005 Posts: 229 Location: Italy - Galatro(RC)
|
Posted: Fri Feb 15, 2008 7:29 pm Post subject: |
|
|
thanks, I'll check _________________ ____________________
______________________
kiu |
|
| Back to top |
|
 |
|