Page 1 of 1

matchText returning where the match was

Posted: Mon Jan 11, 2010 4:23 pm
by massung
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.

Re: matchText returning where the match was

Posted: Mon Jan 11, 2010 10:13 pm
by sturgis
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.

Re: matchText returning where the match was

Posted: Mon Jan 11, 2010 10:25 pm
by massung
Kick ass, it does. Didn't see that one.

Danke.

Jeff M.