Hi guys.
Not many people seem to use Regular Expressions in Stata, particularly the search+replace in Do File editor application.
The flavor of Stata's Regular Expressions is not totally standard which can be a little frustrating. But one weakness I can't seem to find in documentation is how the Find+Replace is able to reference the found selection. Please note: I AM NOT talking about the regex*() commands that exist for dataset filtering, i am in the context of find and replace in dofile editor where you check the box "Regular expression" and can make more advanced finding algorithms in program code. Allow me to demonstrate with an example.
Let's say the contents of the dofile is:
I use the regular expression code in "Find what" field:
This finds all instances of foo(*) where * = all spaces, characters, numbers.
In other implementations of RegEx find and replace (Notepad++ for example) you can use:
as a representation of whatever is "found" in the find+replace diagogue. So if you were to make "Replace with" field:
Then the dofile's contents would then look like:
But Stata's find+replace regex does not recognize $0.
I can't find in the documentation what is the way to reference the found elements. Does anyone know if this is even possible in Stata?
Not many people seem to use Regular Expressions in Stata, particularly the search+replace in Do File editor application.
The flavor of Stata's Regular Expressions is not totally standard which can be a little frustrating. But one weakness I can't seem to find in documentation is how the Find+Replace is able to reference the found selection. Please note: I AM NOT talking about the regex*() commands that exist for dataset filtering, i am in the context of find and replace in dofile editor where you check the box "Regular expression" and can make more advanced finding algorithms in program code. Allow me to demonstrate with an example.
Let's say the contents of the dofile is:
Code:
foo(test 123) bar(456 test)
Code:
foo([^)]*?)
In other implementations of RegEx find and replace (Notepad++ for example) you can use:
Code:
$0
Code:
/* $0 */
Code:
/* foo(test 123) */ bar(456 test)
I can't find in the documentation what is the way to reference the found elements. Does anyone know if this is even possible in Stata?
Comment