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 

what is wrong?

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



Joined: 05 Oct 2005
Posts: 17
Location: china

PostPosted: Thu Jun 14, 2007 4:16 pm    Post subject: what is wrong? Reply with quote

Code:
var := "adbkd%appdata%dkk%windir%dgkkg%homepath%"
regexmatch(var, "%(.+?)%", regvar)
msgbox % regvar1 a_tab regvar2 a_tab regvar3


i think the result will be:
regvar1 is appdata
regvar2 is windir
regvar3 is homepath

but exact result was:
Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
ErrorLevel[1 of 3]: 0
regvar[9 of 63]: %appdata%
regvar1[7 of 7]: appdata
regvar2[0 of 0]:
regvar3[0 of 0]:
var[40 of 63]: adbkd%appdata%dkk%windir%dgkkg%homepath%

what is wrong?
thanks
Back to top
View user's profile Send private message
POINTS



Joined: 18 Jan 2006
Posts: 284

PostPosted: Thu Jun 14, 2007 4:49 pm    Post subject: Reply with quote

For starters take out the quotes. You're telling AHK you want a literal string not dereferenced variables.

Code:
var := adbkd%appdata%dkk%windir%dgkkg%homepath%


If you need adbkd to be a string in there, you might have to do this:

Code:
var := "adbkd" . %appdata%dkk%windir%dgkkg%homepath%

_________________
My AutoHotkey Program for Warcraft III:
Warkeys
http://warkeys.sourceforge.net/

Remap your hotkeys
Healthbars always on
Remap inventory
Back to top
View user's profile Send private message Visit poster's website
TheIrishThug



Joined: 19 Mar 2006
Posts: 370

PostPosted: Thu Jun 14, 2007 5:32 pm    Post subject: Reply with quote

Do you want a string that is literally adbkd%appdata%dkk%windir%dgkkg%homepath% and not a a string that is adbkd[THE VALUE OF appdata]dkk[THE VALUE OF windir]dgkkg[THE VALUE OF homepath]?

If it is the first, like you have in your example, then your issue is that RegexMatch does not find every occurrence of the pattern. If you have a set number for times the same pattern will appear, than you could write the pattern to fit that. eg "%(.+?)%.+%(.+?)%.+?%(.+?)%"

If you need an unknown number of matches, the following should work.

[EDIT]
Looks like did all that work for nothing. Embarassed
Titan wrote a better version a while ago.
LINK
[/EDIT]

Code:
SearchingIn := "adbkd%appdata%dkk%windir%dgkkg%homepath%"
SearchFor := "%(.+?)%"
RegExMatchAll(SearchingIn, SearchFor)
listvars
pause

RegExMatchAll(Haystack, NeedleRegEx, ArrayName = "Match")
{
  Global
  Local pos := -1, regvar, regvar1
  Loop
  {
    pos := pos + StrLen(regvar1) + 2
    If (pos > StrLen(Haystack))
      Break
    pos := regexmatch(Haystack, NeedleRegEx, regvar, pos)
    %ArrayName%%A_Index% = %regvar1%
  }
}
Back to top
View user's profile Send private message Visit poster's website AIM Address
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