Page 1 of 1

matchText for punctuation (solved)

Posted: Sun Oct 11, 2015 3:23 pm
by monki
I'm trying to matchText for the end of sentences, something like "*/[.!?]/" or "*[\.\!\?]" but I can't find a pattern that to match the punctuation that Livecode likes. Any ideas?

Thanks.

Re: matchText for punctuation

Posted: Sun Oct 11, 2015 8:25 pm
by richmond62
I'm not sure if I entirely understand what you are trying to do, but I do see from the Documentation that the way matchText
is explained there is different from your examples:

matchText ["Goodbye","Get Lost"]

I could see no sign of those backslashes.

So, I wonder if you might be better with something like matchText [".","!","?"]

Re: matchText for punctuation

Posted: Sun Oct 11, 2015 9:35 pm
by bn
Hi,

matchtext can be used with regular expressions. From the dictionary
matchText("Goodbye","bye")
matchText("Goodbye","^Good")
matchText(phoneNumber,"([0-9]+)-([0-9]+-[0-9]+)",areaCode,phone)
But as of LC 7 their is a "Sentence" keyword, maybe that helps? Once you parse for sentences you could do the usual chunk operations on them.

Code: Select all

put the number of codepoints of sentence 1 to 3 of field 1 after field 2
Kind regards

Bernd

Re: matchText for punctuation

Posted: Mon Oct 12, 2015 1:41 am
by monki
Yeah, I realize I didn't give enough information in my original post. A bit of frustration and lack of sleep, I guess.

I'm trying to return a boolean on a word, "true" if the word contains ".,?,!", which may, or may not be at the end of the word. So the pattern should be
"some amount of characters","a single sentence closing punctuation mark","maybe a quote, maybe not"

I think the main problem I'm having is that everything I need to match against is a special character. And, my attempts to "escape" them have only generated errors. In an online regular expression tester "*(\.|\?) selects all the "." marks on the page. But anything similar in livecode just tosses up a debugger. I feel that "*(\.|\?|\!)*" should match the words I'm trying to identify, but at this point, it's just a guessing game of unhelpful errors. I'm afraid that I don't understand this part well enough see where I'm going wrong. But that's why we try new things 8)

thanks

Re: matchText for punctuation (solved)

Posted: Mon Oct 12, 2015 2:27 am
by monki
Lucked into it. :D Some quote about monkeys and typewriters seems appropriate.

Here it is if anyone else has a similar problem. Returns true for sentence closing punctuation marks, including those inside quotes.

Code: Select all

matchText(tWord,"[\. \! \?]")