Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Michael Stewart <michaelstewartresearch@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Need help with regular expression |
Date | Sun, 17 Feb 2013 08:22:38 -0500 |
Hi Nick and Alison, One quick question.(sorry, I am a novice to regular expressions) The two functions di regexm("show us", " us$") & di regexm("show us", " us&") have different results. what is the difference between these functions ?? Thank you very much . Sincerely Mike On Sun, Feb 17, 2013 at 5:03 AM, Nick Cox <njcoxstata@gmail.com> wrote: > Alison's suggestion is surely right. If your condition is not > restrictive enough, you need to make it more restrictive. > > If it is a separate word, it occurs surrounded by spaces or at the > beginning or end with one space after or before. I tend to build up > syntax using -display- and little examples. > > . di regexm("us marines", "^us ") > 1 > > . di regexm("show us", " us$") > 1 > > . di regexm("invited us to dinner", " us ") > 1 > > You could also use -strpos()- > > ... if strpos(var, " us ") | strpos(var, "us ") == 1 | strpos(var, " us") == -3 > > Note that -regexm()- is a function, not a command. in Stata functions > and commands are quite separate in definition and documentation. > -strpos()- is another function. Fixing _function_ firmly in mind as > the key term leads to consultation of the documentation on functions, > which as here can suggest alternatives. > > There are also solutions with -word()- but they all seem to entail a loop. > > Nick > > On Sun, Feb 17, 2013 at 8:04 AM, Alison Connor > >> I am sure there is a much better way to do this, but until someone who >> actually knows responds, could you try something like: >> >> regexm(var, " us ") | regexm(var, " us&") | regexm(var, "^us ") ? > > On Sun, Feb 17, 2013 at 1:00 PM, Michael Stewart > >>> I am trying to use regexm command (regexm(var,"us"))to see if the >>> values of variable have a particular string "us" like in "us thyroid" >>> .Unfortunately , it is picking up "us" from other string values like >>> "venous".If there a way to formulate command so that it can pick up >>> only values where "us" is a separate word and not part of word like >>> venous. > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ -- Thank you , Yours Sincerely, Mike. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/