Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Errors in using regexr() and regular expression

    Dear all,

    I encountered a problem when I was trying to use regexr():

    In my standard_name variable there are string like "PSC LLC [EX-PHILIP SERVICES]", of which I wanted to remove the substring "[EX- *]".
    So I tried with the function:
    replace standard_name = regexr(standard_name, "\[(EX-)+\]", " ")
    But the result shows "0 real changes made". I was wondering if there is anything wrong with my code. Many thanks in advance!

    Daisy
    Last edited by Daisy Wang; 24 Jul 2016, 21:45.

  • #2
    Just to correct the quote:
    The true code should be
    replace standard_name = regexr(standard_name," \ [ (EX-) + \ ]") > 0
    Sorry for the auto-transition caused.

    Comment


    • #3
      Read the FAQ on regex http://www.stata.com/support/faqs/da...r-expressions/ and help regexr.

      ​Then compare your code with
      Code:
       regexr( standard_name, "\[EX-.*\]", "" )
      Last edited by Bjarte Aagnes; 25 Jul 2016, 03:06.

      Comment

      Working...
      X