Regexep Plugin

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

Regexep Plugin

Post by schimanke » Fri Jun 03, 2016 9:03 am

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!

User avatar
onli
Regular
Posts: 2263
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Regexep Plugin

Post by onli » Sat Jun 04, 2016 12:24 pm

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 5:38 pm
Location: Hameln, Germany
Contact:

Re: Regexep Plugin

Post by schimanke » Sat Jun 04, 2016 1:28 pm

Yep, that worked!
Thank you very much. You made my day! :)

schimanke
Regular
Posts: 161
Joined: Mon Jan 07, 2008 5:38 pm
Location: Hameln, Germany
Contact:

Re: Regexep Plugin

Post by schimanke » Sat Jun 18, 2016 3:26 pm

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?

User avatar
onli
Regular
Posts: 2263
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: Regexep Plugin

Post by onli » Mon Jun 20, 2016 11:25 am

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