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 

Regular expression match and output array

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



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Fri Feb 15, 2008 6:38 pm    Post subject: Regular expression match and output array Reply with quote

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
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Fri Feb 15, 2008 7:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Fri Feb 15, 2008 7:13 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Fri Feb 15, 2008 7:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
kiu



Joined: 18 Dec 2005
Posts: 229
Location: Italy - Galatro(RC)

PostPosted: Fri Feb 15, 2008 7:29 pm    Post subject: Reply with quote

thanks, I'll check
_________________
____________________
______________________
kiu
Back to top
View user's profile Send private message Visit poster's website
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