Hi everyone,
I just learned how to use the regexr command and I believe it can help solve my problem.
I have a string variable "response":
As you can see, the word 'where' is repeated quite often. I want to replace strings "where where" and "where where where" with "where"
However, I don't want to replace (e.g.) "everywhere where" with "where"
I know I can do this manually, but I was hoping to condense the code into as few lines as possible. This is what I've been trying so far:
Would appreciate any advice! Thanks!
I just learned how to use the regexr command and I believe it can help solve my problem.
I have a string variable "response":
list response
I'm going there
where where did you say
sometimes it is where you think
i think its where where you go
its everywhere where you are
i am planning on going where where where i want to
As you can see, the word 'where' is repeated quite often. I want to replace strings "where where" and "where where where" with "where"
However, I don't want to replace (e.g.) "everywhere where" with "where"
I know I can do this manually, but I was hoping to condense the code into as few lines as possible. This is what I've been trying so far:
gen temp = regexr(response, " (where)+ where ", " where ")I have been using "(where)+" to capture both "where where" and "where where where" but it doesn't seem to work. I also split the code into two commands, one begins with "^(where)" and the other with " (where)" in order to avoid capturing the 'where' in "everywhere" but if I could condense this into one command, that would be ideal as well.
replace temp = regexr(response, "^(where)+ where ", "where ")
Would appreciate any advice! Thanks!
Comment