Announcement

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

  • Possible bug in Mata regexr() function

    What looks like a bug in the Mata regexr() function is reported to tech-support:
    Code:
    . di regexr("A;",";","")
    A
     
    . mata:  regexr("A;",";","")
      A;

  • #2
    Bjarte Aagnes --

    Might this have something to do with ; not being a regular character? I find the following works:

    Code:
    mata: ustrregexrf("A;",";","")
      A
    Best,

    Matthew J. Baker

    Comment


    • #3
      Bjarte Aagnes --

      The plot thickens. While the official Stata documentation says that the mata function regexr applies only to "plain" or "lower" Ascii, a semicolon is included in lower ascii. Another weird thing about this is the following experiment with a few different characters:

      Code:
      . mata: regexr("A:", ":", "")
        A:
      
      . mata: regexr("A!", "!", "")
        A!
      However, I find that things work correctly if I put a space at the end of the expression:

      Code:
      . mata: regexr("A; ", ";", "")
        A
      I'm baffled!

      @Matthew J. Baker



      Comment


      • #4
        More generally, I find this is the case for any character:

        Code:
        mata:
        for (k = 97; k <= 122; k++)  {
            regexr("A" + char(k), char(k), "")
        }
        end
        Will print A followed by a-z. In other words, the last character is not being replaced. Consider:

        Code:
        mata:
        for (k = 97; k <= 122; k++)  {
            regexr(char(k) + "A", char(k), "")
        }
        end

        This just prints "A" all the way! However,

        Code:
        mata:
        for (k = 97; k <= 122; k++)  {
            regexr("A" + char(k), "A" + char(k), "")
        }
        end
        Works just fine (same for addming a space, as noted in the above posts). Sure seems like a bug. Very odd.

        Comment


        • #5
          This has been fixed. Update 20 feb 2019.

          Comment

          Working...
          X