Announcement

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

  • strmatch and backslash

    There seems to be something weird about strmatch, and I just can't find out what. I'm trying to match file names, and I stumbled on a problem that reduces to this:
    Code:
    . di strmatch("a/*","*/*")
    1
    
    . di strmatch("a/b","*/*")
    1
    
    . di strmatch("a\*","*\*")
    1
    
    . di strmatch("a\b","*\*")
    0
    Why is the last one 0? I suspected some kind of special use of backslash (like in C to quote characters), but Stata doesn't do that usually, and anyway di strmatch("a\b","*\\*") also returns 0. And I found nothing about backslash in strmatch in the documentation.

    There is the same problem with:
    Code:
    . di strmatch("a\?","*\?")
    1
    
    . di strmatch("a\b","*\?")
    0
    There is a workaround:
    Code:
    . di regexm("a\b",".*\\.*")
    1
    And here the backslash is doubled because it's the quoting character for regular expressions (e.g., to match the character "*" use "\*").

    Has anyone an explanation for this behaviour of strmatch?

  • #2
    I have no answer. I can say that

    Code:
    . di strmatch("a\b","*\\*")
    1
    used to work in Stata 11 and 12.

    Beste
    Daniel

    Comment

    Working...
    X