Page 1 of 1

Exiting matchChunk() gracefully with invalid regex entry

Posted: Thu Nov 22, 2018 9:45 am
by kaveh1000
I have a handler that takes regex input from a user and uses it to find text in a field. The user puts a regex in a box. This is the_search. In a handler I have:

Code: Select all

   put "(" & the_search & ")" into the_search
   get matchChunk(fld "text", the_search, the_start, the_end)
 
The first line puts in the parenthesis so I can find the position of the item found.

The problem arises when the user puts in an invalid regex, e.g. abc [0. I get an execution error at matchChunk. I want something to simply exit the handler if there is erroneous entry. Any ideas pls?

Re: Exiting matchChunk() gracefully with invalid regex entry

Posted: Thu Nov 22, 2018 10:32 am
by Klaus
Hi Kaveh,

can't you just TRY this?

Code: Select all

...
put "(" & the_search & ")" into the_search
try
  get matchChunk(fld "text", the_search, the_start, the_end)
catch errNum
  answer "Idiot!"
end try
...
Best

Klaus

Re: Exiting matchChunk() gracefully with invalid regex entry

Posted: Thu Nov 22, 2018 3:00 pm
by kaveh1000
Klaus does it again! Thank you. Yes, I had forgotten "try". One of these days, RTFM again. ;-)

Re: Exiting matchChunk() gracefully with invalid regex entry

Posted: Thu Nov 22, 2018 6:46 pm
by kaveh1000
As an added bonus, if there is indeed an error in matchChunk, I am setting the backgroundcolor of the regex field to a colour, so there is real time feedback that the text is not a valid regular expression. :-)