 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ginandtonic Guest
|
Posted: Mon Nov 23, 2009 9:35 pm Post subject: Trouble with regexmatch() |
|
|
I'm trying to find each word in the sentence and store it in word%a_index%.
| Code: | pos = 1
sentence = Test this sentence, okay?
done := strLen(sentence)
while (pos < done)
{
pos := RegExMatch(sentence, "([a-zA-Z]+)", temp, %pos%)
word%a_index% := temp1
pos := pos + strLen(temp1)
displayword := word%a_index%
msgbox %pos%`n%temp1%`n%sentence%`n%displayword%
}
^x::ExitApp |
I get the output:
0
Test this sentence, okay? |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Mon Nov 23, 2009 11:10 pm Post subject: |
|
|
| Code: | sentence = Test this sentence, okay?
StringSplit, word, sentence, %A_Space%
Loop, %word0%
MsgBox,% word%A_Index% |
|
|
| Back to top |
|
 |
rtcvb32
Joined: 17 Feb 2008 Posts: 289
|
Posted: Tue Nov 24, 2009 1:36 am Post subject: |
|
|
Before splitting the sentence by spaces, you may want to combine all the unwanted non-words and convert them to spaces. Since punctuation would get confused as words, unless that's not important.
| Code: |
newsentence := RegexReplace(sentence, "\W+", " ")
StringSplit, word, newsentence, %A_Space%
|
|
|
| Back to top |
|
 |
nick
Joined: 24 Aug 2005 Posts: 549 Location: Berlin / Germany
|
Posted: Tue Nov 24, 2009 4:21 pm Post subject: |
|
|
| Code: | #NoEnv
sentence = Test this sentence, okay?
pos = 1
counter = 0
While (pos := RegExMatch(sentence, "[a-zA-Z]+", temp, pos + StrLen(temp)))
{
counter++
word%a_index% := temp
displayword := word%a_index%
MsgBox Word: %counter%`nPosition: %pos%`n%temp%`n%sentence%`n%displayword%
}
ExitApp
^x::ExitApp |
_________________ nick  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|