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

st: Regular Expression Double Escape: \\

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

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.


**************************CODE BEGINS**************************
input str10 item

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

*   For searches and help try:

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