Statalist


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

st: Regular Expression Double Escape: \\


From   Steven Samuels <[email protected]>
To   [email protected]
Subject   st: Regular Expression Double Escape: \\
Date   Fri, 31 Oct 2008 11:43:17 -0400

In http://www.stata.com/statalist/archive/2005-09/msg00364.html,   
Frank de Libero posted a summary of Stata's implementation of regular  
expressions  which he had received from Kevin Turner of StataCorp.   
It contained the statement that "... denoting a literal dollar sign  
could be done with \$"

This was incorrect.  "$" is a reserved Stata character--it is used in  
the definition of global macros.
To match a literal dollar sign, one needs a double backslash, "\\$".

Thanks to Kerry Kammire of StataCorp for setting me straight.

-Steve


**************************CODE BEGINS**************************
input str10 item
"$10,000"
end

gen str10 item_w = regexr(item,"\\$","A")   //Matches literal "$"
gen str10 item_x = regexr(item,"\$","A")    //Matches end position
gen str10 item_y = regexr(item,"$","A")     //Matches end position
list
***************************CODE ENDS***************************


*
*   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