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?
0 Response to strmatch and backslash
Post a Comment