Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: subinstr and special characters ? and *


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: subinstr and special characters ? and *
Date   Fri, 13 Aug 2010 11:40:59 +0100

-subinstr()- is very literally-minded. It will not recognise wildcards
or regular expressions. You should consider using regex machinery. 

[D]     functions . . . . . . . . . . . . . . . . . . regexm() string
function
        (help regexm())

[D]     functions . . . . . . . . . . . . . . . . . . regexr() string
function
        (help regexr())

[D]     functions . . . . . . . . . . . . . . . . . . regexs() string
function
        (help regexs())

FAQ     . . . . . . . . . . . . . . . . . . . . . . . . .  Regular
expressions
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . K. S.
Turner
        10/05   What are regular expressions and how can I use
                them in Stata?
                http://www.stata.com/support/faqs/data/regex.html

FAQ     . How to extract a portion of a string var. using regular
expressions?
        . . . . . . . . . . . . . . . . . .  UCLA Academic Technology
Services
        7/08    http://www.ats.ucla.edu/stat/stata/faq/regex.htm

Nick 
n.j.cox@durham.ac.uk 

A Loumiotis

Is there a way to use subinstr to replace a pattern that is given with
the special characters ? or * with something else?

For example:

local a p_2_3456
local b: subinstr local a "_?_" "__"
di "`b'"
local b=subinstr("`a'","_?_","__",1)
di "`b'"

I would expect that b will now be p__3456 but subinstr does not
recognize _?_ to include _2_ .
Is there anyway to do this?

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index