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

Re: st: regexr: escaping nested quotes within strings

From   Maarten buis <>
Subject   Re: st: regexr: escaping nested quotes within strings
Date   Thu, 11 Sep 2008 21:11:37 +0100 (BST)

--- Tobias Gramlich <> wrote:
> 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?

What might help to solve part of the problem are compound quotes, see:
-help quotes-

*------------ begin example ----------------
drop _all
set obs 1
gen company = `""Hotel "ABC"""'
di company
generate x=subinstr(company,`"""',"",.)
di x
*------------- end example -----------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

*   For searches and help try:

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