WordPress.org

Ready to get started?Download WordPress

Forums

Twitter Widget Pro
[resolved] [GIFT] Improved #hashtags regex to match accentuated characters (10 posts)

  1. Vivien Garcia
    Member
    Posted 1 year ago #

    Hi there
    First : thanks very much for this great plugin which helps me a lot.

    So I'm French and I use accentuated characters in hashtags. The original regex couldn't match with those hashtags, so I've tweaked it a bit.

    Regex is situated in : /[your_plugin_directory]/wp-twitter-widget.php at line 451 – in public function linkHashtags().

    Just replace the preg_replace_callback() regex :
    '/(^|\s)(#\w*)/i'

    by this one :
    '/(^|\s)(#[a-zA-Z0-9ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]*)/i'

    I'm not a programmer so I suppose this code isn't very nice and smart but I does the job for me.

    I hope it will help someone as it helped me. :-)

    http://wordpress.org/extend/plugins/twitter-widget-pro/

  2. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    Can you test this regex to see if it works as you expect:
    '/(^|\s)(#[\w\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{00FF}]*)/i'

    It should still account for all the characters you added as well as a few more. Let me know how it works and I'll try to incorporate it into the next version.

  3. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    This new regex is in 2.4.0 ... please download it and see how it works for you!

  4. Fabio.Gomez
    Member
    Posted 1 year ago #

    Hello,

    Thank you Vivien, it works like a charm.

    Aaron, same problem over here, with Spanish hashtags, I'm using the last version, 2.4.0, with the regex you had posted, and it doesn't work either.

    Thank you for such a great plugin.

    Regards,

  5. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    Can you link to some tweets that have characters that aren't working?

  6. Fabio.Gomez
    Member
    Posted 1 year ago #

  7. Aaron D. Campbell
    Member
    Plugin Author

    Posted 1 year ago #

    There was a u left off the end of the regex. /i should be /iu. I fixed it in version 2.4.1, so as soon as that propagates through the repository and you update this should be fixed.

  8. elimc
    Member
    Posted 9 months ago #

    This seems like it would be less complicated, and possibly more inclusive:

    /(^|\s)(#\S+)/i

    You can test out regexp, here: http://gskinner.com/RegExr/

  9. Aaron D. Campbell
    Member
    Plugin Author

    Posted 9 months ago #

    There are characters that are not allowed in URLs that should be ignored when trying to match URLs. There are also characters that ARE allowed but are rarely used *in* URLs and are often used to delineate. Here are some samples that I'm trying to link as the user expects:

    1. I visited http://wordpress.org. You should too.
    2. I visited http://wordpress.org, said Alice.
    3. I visited http://wordpress.org; it prompted me to take action and get involved.
    4. Quote from http://wordpress.org: Code is Poetry
    5. WordPress (http://wordpress.org) is a great platform.

    In each of those the user really wants http://wordpress.org to be linked. They don't want the trailing character linked .,;:)

  10. elimc
    Member
    Posted 9 months ago #

    I was using my regexp for hashtags and not links, but I understand your concern. If someone does:

    I went to the #store.

    There will be an issue. At the same time, under your current code, if someone did:

    I went to #7.11

    There will also be an issue . . . if I understand correctly. I know no one will use 7.11, but I couldn't think of another example. Anyway, the point is that I guess you have to pick and choose?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic