Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: regex-syntax error: "regexp: unmatched []"; no possibility to stop the do-file


From   Steven Samuels <[email protected]>
To   [email protected]
Subject   Re: st: regex-syntax error: "regexp: unmatched []"; no possibility to stop the do-file
Date   Mon, 26 Jan 2009 10:52:55 -0500


Your example does not work, because -regexm- requires a string variable for an argument. Please give a realistic example of observations that do and do not generate the error message. The problem with your code is that the regular expression should be "\ [\]" because "[" and "]" have special meanings for regular expressions: they denote the ranges of characters to be matched.


-Steve



On Jan 26, 2009, at 10:30 AM, Inna Becher wrote:

Dear stata-listers,
I have a problem with stata-regular expressions. Here is an example:

/*--- example ---*/
preserve
clear
set obs 5

gen v1=.

replace v1=1 if regexm(v1,"[]")==1
display _rc

restore
/*--- end example ---*/

The regex-command returns the return code "0", but there are  several
red  error  messages  because  of  the  regex-syntax  error  "regexp:
unmatched []".
Since our  real data  has about  30mio. observations  and the  syntax
error message is printed out for  every single observation, we  would
like to stop  the  regex   command with  the  first  "error"  message
"regexp: unmatched []". Since there is no useful return code (in fact
there is  the  return  code 0  after complete  execution of the regex
command),   we would like  to  know  how  to kill the  command  after
the  first  occurence of  "regexp:  unmatched []" automatically.

There is  even no  chance of  stopping the  program by  pressing  the
break button after a "more"-condition.

Is there a way to stop the execution after the first occurence of the regex error message "regexp: unmatched []"?


Thanks in advance for your help,

Inna Becher





*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index