Page 1 of 1

regex and emoji

Posted: Sat Jun 22, 2019 6:42 pm
by Rjevsky
Hello to all! I have a problem with the code.

Code: Select all

        If CreateRegularExpression(0, "(.+?)\|(.+?)")
          If ExamineRegularExpression(0, " :evil: | :twisted: ")
            While NextRegularExpressionMatch(0)
              RegularExpressionGroup(0, 1)
              If OpenFile(0, "test.txt")  
                FileSeek(0, Lof(0)) 
                WriteStringN(0, RegularExpressionGroup(0, 1)+RegularExpressionGroup(0, 1))
                WriteStringN(0, " :evil:  :twisted: ")
                CloseFile(0) 
              EndIf 
            Wend
          EndIf
        Else
          Debug RegularExpressionError()
        EndIf
Replace this smiles to emoji from here: https://getemoji.com like this:
Image
(I can't insert normal code due to forum problems)

Result:
Image

Why are emoji in string #1 lost?

Re: regex and emoji

Posted: Sat Jun 22, 2019 7:21 pm
by Little John

Code: Select all

        If CreateRegularExpression(0, "(.+?)\|(.+?)")
          If ExamineRegularExpression(0, " :evil: | :twisted: ")
            While NextRegularExpressionMatch(0)
      -->     RegularExpressionGroup(0, 1)   <--- remove this line
              If OpenFile(0, "test.txt")  
                FileSeek(0, Lof(0)) 
                WriteStringN(0, RegularExpressionGroup(0, 1)+RegularExpressionGroup(0, 1))
                WriteStringN(0, " :evil:  :twisted: ")
                CloseFile(0) 
              EndIf 
            Wend
          EndIf
        Else
          Debug RegularExpressionError()
        EndIf
What is the purpose of the marked line?
My suggestion: Remove it and see whether the code then works as desired.
Replace this smiles to emoji from here: https://getemoji.com/like this:
404 Not Found.

Re: regex and emoji

Posted: Sat Jun 22, 2019 8:33 pm
by Rjevsky
Little John wrote: What is the purpose of the marked line?
My suggestion: Remove it and see whether the code then works as desired.
Yes, this is an extra line, but it does not solve the problem.
Little John wrote: 404 Not Found.
Fixed.

Re: regex and emoji

Posted: Sat Jun 22, 2019 9:35 pm
by #NULL
Somehow it doesn't work, but I don't know if that is supported and/or if there is a problem with multibyte sequences. The ape is 4 bytes in a pb utf-16 string.
I used this one (replace x in code): https://emojipedia.org/hear-no-evil-monkey/

Code: Select all

Debug "test:" + "x" ; (make sure you debug window font can display it)

If CreateRegularExpression(0, "(x)")
  If ExamineRegularExpression(0, "x")
    While NextRegularExpressionMatch(0)
      Debug "group:" + RegularExpressionGroup(0, 1)
    Wend
  EndIf
Else
  Debug RegularExpressionError()
EndIf

Re: regex and emoji

Posted: Sat Jun 22, 2019 10:58 pm
by Derren
I don't know what your code is supposed to do. it doesn't put both emojis into the file.
But the first one is put into the file correctly.
And if I switch it for the monkey that #NULL used, it works as well.

Re: regex and emoji

Posted: Sun Jun 23, 2019 6:19 am
by #NULL

Code: Select all

s.s = Space(2)
PokeQ(@s, 3729381437)

Debug "test:" + s ; (make sure you debug window font can display it)

If CreateRegularExpression(0, s+"abc")
  If ExamineRegularExpression(0, s+"abc")
    While NextRegularExpressionMatch(0)
      Debug "match:" + RegularExpressionMatchString(0)
    Wend
  EndIf
Else
  Debug RegularExpressionError()
EndIf
I only get xab, not xabc. If I use a double ape I only get xxa, which tells me there is something wrong with character/byte count.

(Linux 64)