matchText returning where the match was

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

Post Reply
massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

matchText returning where the match was

Post by massung » Mon Jan 11, 2010 4:23 pm

Right now matchText simply returns true or false indicating that the regular expression did - indeed - find a match somewhere in the input string. It would be extremely helpful to know where in the string the match was found. The best that's possible right now is to use matchText in conjuction with find, but that can yield false-positives. For example:

Code: Select all

local tFoundText

if matchText(field "Whatever", "(\bif\b)", tFoundText) is true then
   find tFoundText in field "Whatever"
end if
But that doesn't work, because the find command will match "blahifblah", whereas the matchText won't.

Jeff M.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: matchText returning where the match was

Post by sturgis » Mon Jan 11, 2010 10:13 pm

Doesn't matchChunk do what you want? Behaves the same as matchtext except it returns the position information for the match..
massung wrote:Right now matchText simply returns true or false indicating that the regular expression did - indeed - find a match somewhere in the input string. It would be extremely helpful to know where in the string the match was found. The best that's possible right now is to use matchText in conjuction with find, but that can yield false-positives. For example:

Code: Select all

local tFoundText

if matchText(field "Whatever", "(\bif\b)", tFoundText) is true then
   find tFoundText in field "Whatever"
end if
But that doesn't work, because the find command will match "blahifblah", whereas the matchText won't.

Jeff M.

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: matchText returning where the match was

Post by massung » Mon Jan 11, 2010 10:25 pm

Kick ass, it does. Didn't see that one.

Danke.

Jeff M.

Post Reply