Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7487983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:42:25+00:00 2026-05-29T14:42:25+00:00

Working example: http://alpha.jsfiddle.net/gTpWv/ Both of the methods work separately, but once regexp for smilies

  • 0

Working example: http://alpha.jsfiddle.net/gTpWv/

Both of the methods work separately, but once regexp for smilies gets raw HTML code to process, things get ugly.

    K = K.replace(/\b((http:\/\/)|(www\.))[^ ]{5,}/g, function (x) {
    var b = x;
    if (b.indexOf("www") == 0) {
        b = "http://" + b
    }
    return '<a href="' + b + '" target="_blank">' + x + "</a>"
// K is now /"Testing <a href="http://www.google.com," target="_blank">http://www.google.com,</a> :D, ^^"/


    for (var d = 0; d < smiliesArray.length; d++) {
        K = K.replace(new RegExp(smiliesArray[d][0], "g"), '<img src="' + smiliesArray[d][1] + '">');
    }
// K is now Testing <a href="http%3Cimg%20src=" http:="" i.imgur.com="" mvk87.gif"="">/www.google.com," target="_blank"&gt;http<img src="http://i.imgur.com/MVk87.gif">/www.google.com,</a> <img src="http%3Cimg%20src=" http:="" i.imgur.com="" mvk87.gif"="">/i.imgur.com/7JJNL.gif"&gt;, <img src="http%3Cimg%20src=" http:="" i.imgur.com="" mvk87.gif"="">/i.imgur.com/vRgA3.gif"&gt;

I did find regexp claiming to solve this issue, but inserting it into the regexp: http://alpha.jsfiddle.net/gTpWv/1/ returns nothing.

I’ve also found interesting the idea to follow this procedure, but I would be left with two seperate lines, one with links and one with smilies and it would take another regexp to inject one into another.

I’m not sure should I meddle with a better regexp(s) or try to find another way to solve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:42:26+00:00Added an answer on May 29, 2026 at 2:42 pm

    The problem is that :/ will be caught in places where it shouldn’t. Every time K changes during replaces, it is fed with some http:// strings that contain the seeds of evil… the :/ bits. At the next iteration, these will be replaced with the corresponding enter image description here smilie, corrupting the generated HTML stored in K.

    My approach was to do a 2-phase search and replace. See it in action here http://alpha.jsfiddle.net/gTpWv/7/, and read on for further explanation.

    We start by changing every url and smilie to intermediate forms. To use your example string "Testing www.google.com, :D, ^^ :/":

    $each(N.split("\n"), function(K) {
        // First pass: creating url and smilie maps
        var urlSubstitutions = [];
        var smilieSubstitutions = [];
    
        K = K.replace(/\b((http:\/\/)|(www\.))[^ ]{5,}/g, function(match) {
            var b = match;
            if (b.indexOf("www") == 0) {
                b = "http://" + b
            }
    
            urlSubstitutions.push({ anchor: match, url: b });
            return "{{_u_" + urlSubstitutions.length + "_}}";
        });
    
        for (var d = 0; d < smiliesArray.length; d++) {
            K = K.replace(new RegExp(smiliesArray[d][0], "g"), function(x){
                smilieSubstitutions.push({ smilie: x, image: smiliesArray[d][1] });
                return "{{_s_" + smilieSubstitutions.length + "_}}";
            });
        }
    

    By now, K will contain Testing {{_u_1_}} {{_s_1_}}, {{_s_2_}} {{_s_3_}}. I hope it’s clear that these {{}} strings are the aforementioned intermediate forms of urls and smilies. The actual values of these strings are stored in two arrays named urlSubstitutions and smilieSubstitutions. The next step is simply to decode the intermediate forms into their formatted versions:

        // Second pass: applying urls and smilies
        K = K.replace(/{{_u_(\d+)_}}/g, function(match, index) {
            var substitution = urlSubstitutions[parseInt(index)-1];
            return '<a href="' + substitution.url + '" target="_blank">' + substitution.anchor + "</a>";
        });
    
        K = K.replace(/{{_s_(\d+)_}}/g, function(match, index) {
            var substitution = smilieSubstitutions[parseInt(index)-1];
            return '<img src="' + substitution.image + '">';
        });
    
        document.write(K)
    });
    

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This example working great because here containment is body http://jsfiddle.net/roXon/hMmbK/2/ when i use container
I'm working on a jquery carousel. You can see the example here: http://jsfiddle.net/6fwbS/2/ Click
i have a problem with the revert speed. Here is a working example http://www.jsfiddle.net/V9Euk/94/
Here is a working example: http://jsfiddle.net/FzZwt/8/ If I pass false to the toggle() first
Working example: http://jsfiddle.net/JVVcA/ HTML: <fieldset id=data-page> <legend>data-page</legend> <button rel=page1>Highlight page one</button> <button rel=page2>Highlight page
im following this example http://jsfiddle.net/rniemeyer/badZb/ . I just copy and paste the exact code
Does anyone has the code to a full working example of slartoolkit ( http://slartoolkit.codeplex.com/
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
I've an example sencha touch2 application. It is working fine in my localhost browser(http://localhost/sencha/examples/navigationview/index.html).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.