Regexep Plugin

Creating and modifying plugins.
Post Reply
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Regexep Plugin

Post by schimanke »

Hi!

I hope somebody can help me with a question regarding an expression within the Regexp Plugin. I need to replace a string like
\ud83d\ude0a\ud83d\ude0a\ud83d\ude0a
This basically an ASCII representation of emojis which do not get interpreted. I have played around a little with the plugin and ended up with

Code: Select all

$regexpArray = array(
    'SearchArray' => array("/[^\w]\\\u([\w]+)/i"),
    'ReplaceArray' => array(' test')
); 
However, this will only replace the first occurence of \u until the next backslash appears. In the example above this would result in
test\ud83d\ude0a\ud83d\ude0a
Does anybody have an idea what expression I have to configure to replace the hole string?

Thanks in advance!
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Regexep Plugin

Post by onli »

This should work:

Code: Select all

/[^\w](\\\u([\w]+))+/i
Slightly related: If you use mysql, there is currently a bug preventing emoji from being stored. We use the wrong UTF8 encoding in the database. This is the big current bug to fix for s9y 2.2, https://github.com/s9y/Serendipity/issues/394.
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Regexep Plugin

Post by schimanke »

Yep, that worked!
Thank you very much. You made my day! :)
schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 4:38 pm
Location: Hameln, Germany
Contact:

Re: Regexep Plugin

Post by schimanke »

Okay, I recently ran into another problem. Is it possible to extend the Regexep Plugin to not only handle the text within the comments feld but also the text entered into the name field?
onli
Regular
Posts: 2825
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Regexep Plugin

Post by onli »

What is your use case exactly?

The easiest way would be to do this in your theme. In the commentform template, you can use the html55 feature of input patterns to show your users what is allowed.
Post Reply