MatchText to a period?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
shawn
Posts: 18
Joined: Sat Jan 02, 2010 4:11 am

MatchText to a period?

Post by shawn » Wed Jan 06, 2010 5:10 pm

In the following code:

Code: Select all

on mouseUp
   put "Trial" into CurrentWord
   answer matchText(CurrentWord, ".")
end mouseUp
Why is matchText evaluating to true? There is no period in CurrentWord.

My real code is basically looking through a bunch of text word by word and looking for a period using matchtext to the currentword to see if it is at the end of a sentence. MatchText returns true for every word.

What am I doing wrong?

Thanks,

Shawn

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: MatchText to a period?

Post by bn » Wed Jan 06, 2010 8:24 pm

Hi Shawn,
welcom to the forum.
your script returns true because "." has a special meaning in regular expressions. And that is what matchText is using. I find regular expressions (or regex) difficult, because the syntax is, well, difficult for me. Look in the dictionary and the user guide for some hints on regular expressions. And than there is in the plugins section of the development menu a plug-in Regex-builder by Frédéric Rinaldi. I use that for building regular expressions, and often it works. In your case I went to this plug-in and got this:

Code: Select all

answer MatchText(CurrentWord,"(\.)")
and this worked for me. the backslash tells the regular expression to escape = take literally the period that follows. Otherwise a period means any single character.
From the user guide p. 184
. matches any single character (except a linefeed)
A.C matches "ABC" or "AGC", but not "AC" or "ABDC"
Depending on what you want you might also look at the offset function. This function looks for plain text. And can be used repeatedly to find all occurences if you set the charsToSkip variable.
If you need help with this just post your questions.
regards
Bernd
PS There are people here on the forum who know a lot more about regular expressions then I do, but I thought I give it a try to get you going with your script. :)

Post Reply