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 

Trouble with regexmatch()

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ginandtonic
Guest





PostPosted: Mon Nov 23, 2009 9:35 pm    Post subject: Trouble with regexmatch() Reply with quote

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

PostPosted: Mon Nov 23, 2009 11:10 pm    Post subject: Reply with quote

Code:
sentence = Test this sentence, okay?
StringSplit, word, sentence, %A_Space%
Loop, %word0%
 MsgBox,% word%A_Index%
Back to top
View user's profile Send private message Visit poster's website
rtcvb32



Joined: 17 Feb 2008
Posts: 289

PostPosted: Tue Nov 24, 2009 1:36 am    Post subject: Reply with quote

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
View user's profile Send private message Yahoo Messenger
nick



Joined: 24 Aug 2005
Posts: 549
Location: Berlin / Germany

PostPosted: Tue Nov 24, 2009 4:21 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
Display posts from previous:   
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