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 8168833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:39:30+00:00 2026-06-06T20:39:30+00:00

I have done some stuff in jQuery and Javascript before, but unfortunately I am

  • 0

I have done some stuff in jQuery and Javascript before, but unfortunately I am no expert. I couldn’t find any hints on how to accomplish my task with using as few resources as possible. You guys can probably help me out:

Here is what I want to do:

I want to find (using regex) all BB-code-like elements on a page that look something like this:

[ndex here=parameter randomdata]

I want to then replace each of them with the contents I receive from an ajax-call that looks like this:

call.php?ndex=here=parameter randomdata

or whatever parameters I pick up from within the according [ndex]-tag.

Here is my solution/thought-process so far:

$(document).ready(function() {
    var pattern = /\[ndex\s+(.*?)\]/mg;
    var documentText = $(document.body).text();
    var matches = documentText.match(pattern);

    $('*').each(function () { 
        var searchText = this;
        if ($(searchText).children().length == 0) { 
            $.each(matches, function() {
                //here is where I would need to check for a match and make a call 
                }
            }); 
        } 
    });
});

I don’t really know how to work from here. My sketch seems really clunky and complicated. There must be a more elegant and straight-forward solution.

Thank you guys so much for your help. 🙂

  • 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-06-06T20:39:31+00:00Added an answer on June 6, 2026 at 8:39 pm

    i would do something like this :

    function ndex_treat(n) {
      // If element is ELEMENT_NODE
      if(n.nodeType==1)
      {
        // If element node has child, we pass them to function ndex_treat
        if(n.hasChildNodes())
          for(var i= 0; i<n.childNodes.length; i++)
            ndex_treat(n.childNodes[i]);
      }
      // If element is TEXT_NODE we replace [ndex ...]
      else if(n.nodeType==3)
      {
        var matches, elemNdex, elemText;
        // While there is one
        while(/\[ndex\s+(.*?)\]/m.test(n.nodeValue))
        {
          // Taking what's before (matches[1]), the "attribute" (matches[2]) and what's after (matches[3])
          matches= n.nodeValue.match(/^([\s\S]*?)\[ndex\s+(.*?)\]([\s\S]*)$/m)
          // Creating a node <span class="ndex-to-replace" title="..."></span> and inserting it before current text node element
          elemNdex= document.createElement("span");
          elemNdex.className= 'ndex-to-replace';
          elemNdex.title= matches[2];
          n.parentNode.insertBefore(elemNdex, n);
          // If there was text before [ndex ...] we add it as a node before
          if(matches[1]!=="")
          {
            elemText = document.createTextNode(matches[1]);
            elemNdex.parentNode.insertBefore(elemText, elemNdex);
          }
          // We replace content of current node with what was after [ndex ...]
          n.nodeValue=matches[3];
        }
      }
    }
    
    $(function(){
      // Get the elements we want to scan ( being sharper would be better )
      $('body').each(function(){
        // Passing them to function ndex_treat
        ndex_treat(this);        
      });
    
      // Make the ajax calls
      $('.ndex-to-replace').each(function(){
        // Don't know if necessary
        var current= this;
        $.get('call.php?ndex='+encodeURIComponent(this.title),function(data){
          $(current).replaceWith(data);
        });
      });
    });
    

    i replaced by node rather than by jquery because i find it rather bad to work on textNode with jquery. if you don’t care and would rather do the barbarian way, you could replace all the first part with simply :

    $(function(){
      // Get the elements we want to scan ( being sharper would be better )
      $('body').each(function(){
        // With no " in argument of [ndex ...]
        $(this).html( $(this).html().replace(/\[ndex\s+([^"]*?)\]/mg,'<span class="ndex-to-replace" title="$1"></span>') );
        // With no ' in argument of [ndex ...]
        //$(this).html( $(this).html().replace(/\[ndex\s+([^']*?)\]/mg,'<span class="ndex-to-replace" title='$1'></span>') );
      });
    
      // Make the ajax calls
      /* ... */
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to WiX but I have done some stuff with Installshield and
I have done quite some cocoa-touch stuff, but am still new to cocoa. I
Have done some research and found some stuff that may be helpful. I would
This is uni assignment and I have already done some stuff. Please go to
I have done some looking and I found this: http://www.codeproject.com/Articles/14439/The-ScrollableListBox-Custom-Control-for-ASP-NET-2 but to me it
I have done some commits and pushed them into my repository. Then I did
I have done some research and it really seems that implementing a transaction system
I have done some digging out here and am still a little unsure how
I have done some project in Irrlicht and it compiles all well, however when
I have done some research, and majority of the examples I have found use

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.