regex and emoji

Just starting out? Need help? Post your questions and find answers here.
Rjevsky
User
User
Posts: 23
Joined: Tue Jul 18, 2017 3:41 pm

regex and emoji

Post 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?
Last edited by Rjevsky on Sat Jun 22, 2019 8:29 pm, edited 1 time in total.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: regex and emoji

Post 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.
Rjevsky
User
User
Posts: 23
Joined: Tue Jul 18, 2017 3:41 pm

Re: regex and emoji

Post 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.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: regex and emoji

Post 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
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: regex and emoji

Post 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.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: regex and emoji

Post 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)
Post Reply