DISQUS

Blog by Andrea Olivato: Private: Using Regular Expressions to add links to tweets

  • Rob · 1 month ago
    You need to modify the "complete example" because the link translation must take place first. Otherwise, all the previous links created are corrupted.
  • Andrea Olivato · 1 month ago
    Oh you're definitely right! Thanks a lot
  • loige · 1 week ago
    Really useful :) thanks!

    Here's a javascript equivalent function, based on your tutorial :)


    function twitterAddLinks(text)
    {
    return text.replace( /http([s]?):\/\/([^\ \)$]*)/,
    'http$1://$2')
    .replace(/@([a-zA-Z0-9_]*)/,
    '@$1')
    .replace(/\#([a-zA-Z0-9_]*)/,
    '\#$1');
    }
  • loige · 1 week ago
    Ops... i forgot the global search flag :P here's a new version of the javascript function...


    function twitterAddLinks(text)
    {
    return text.replace( /http([s]?):\/\/([^\ \)$]*)/g,
    'http$1://$2')
    .replace(/@([a-zA-Z0-9_]*)/g,
    '@$1')
    .replace(/\#([a-zA-Z0-9_]*)/g,
    '\#$1');
    }
  • loige · 1 week ago
    Sorry, I don't know if there's a way to paste code on disquis... so check the code on pastebin: http://pastebin.com/f69796c47
  • Andrea Olivato · 1 week ago
    Yeah unfortunately there are some problem with pasted snippets. Thanks a lot for your JS suggestion, will update my original article linking at your comment.
  • loige · 1 week ago
    Thanks to you for the great article ;)
    [ e dato che siamo entrambi italiani te lo dico anche in italiano: GRAZIE A TE ;p ]