It is currently Sun Dec 08, 2019 11:03 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: regex and emoji
PostPosted: Sat Jun 22, 2019 6:42 pm 
Offline
User
User

Joined: Tue Jul 18, 2017 3:41 pm
Posts: 14
Hello to all! I have a problem with the code.

Code:
        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.

Top
 Profile  
Reply with quote  
 Post subject: Re: regex and emoji
PostPosted: Sat Jun 22, 2019 7:21 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3715
Location: Berlin, Germany
Code:
        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.

Quote:
Replace this smiles to emoji from here: https://getemoji.com/like this:

404 Not Found.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: regex and emoji
PostPosted: Sat Jun 22, 2019 8:33 pm 
Offline
User
User

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


Top
 Profile  
Reply with quote  
 Post subject: Re: regex and emoji
PostPosted: Sat Jun 22, 2019 9:35 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1158
Location: right here
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: regex and emoji
PostPosted: Sat Jun 22, 2019 10:58 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 221
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: regex and emoji
PostPosted: Sun Jun 23, 2019 6:19 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1158
Location: right here
Code:
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)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye