Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: regexr: escaping nested quotes within strings


From   Tobias Gramlich <Tobias.Gramlich@uni-konstanz.de>
To   statalist@hsphsun2.harvard.edu
Subject   st: regexr: escaping nested quotes within strings
Date   Thu, 11 Sep 2008 21:32:52 +0200

Dear Statalist,

i have a problem with the implementation of the regular expressions in stata;

i try to match (actually replace) one ore more single double quotes  
(") nested within a string variable (as this is typical for example  
some company names, e.g. "Hotel "ABC"");

Since there is no escape character for "normal" characters but for  
example the regular expression anchors ^ or $ i can't do (as this is  
the case e.g. for the script language AWK):

.generate x=regexr(company,""","")  or
.generate x=regexr(company,"\"","")

which both give the error
.too few quotes
.r(132);

The same is (of course) true for using the string function subinstr:

.generate x=subinstr(company,""","",.)
too few quotes
r(132);

To be clear: suppose one company name in the variable company is  
"Hotel "ABC"", so i want to replace the double quotes within the  
string to get "Hotel ABC" (or say Hotel ABC without any quotes)

Is there a way of escaping the quotes so i can match them using the  
regular expression implementation or is there another way of replacing  
them using the string functions?

Thanks in advance for any hint why i'm wrong or any idea on how to  
solve this problem.

Best regrads,
Tobias Gramlich






*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index