| View previous topic :: View next topic |
| Author |
Message |
vital
Joined: 05 Oct 2005 Posts: 17 Location: china
|
Posted: Thu Jun 14, 2007 4:16 pm Post subject: what is wrong? |
|
|
| 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 |
|
 |
POINTS
Joined: 18 Jan 2006 Posts: 284
|
Posted: Thu Jun 14, 2007 4:49 pm Post subject: |
|
|
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 |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 370
|
Posted: Thu Jun 14, 2007 5:32 pm Post subject: |
|
|
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.
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 |
|
 |
|