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

  • Home
  • SEARCH
  • 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 3956522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:22:27+00:00 2026-05-20T02:22:27+00:00

I have a piece of code that searches through a table looking for a

  • 0

I have a piece of code that searches through a table looking for a certain phrase. Once it finds the phrase, it returns the innerHTML of the current cell to a div near the top of the page.

The problem I am having is this :

The code works flawlessly unless the phrase being searched for contains any special characters (brackets and ampersands etc). I have tried modifying the phrase from “Western & Central" to "Western & Central" but unfortunately the code is still unable to locate the phrase.

Heres the code:

// Function for searching tables for specific map/device combination.
function findMap(map, device)
{
var flag = false;   // to check if the map has been found yet

// Add <strong> tags to map string so it is easier to search for
var mapstring = "<strong>" + map;
var map_regex = new RegExp( mapstring,'i');

// create array of tables
var tables = document.getElementsByTagName('table');

for (var t = 2; t < tables.length; t++)
{
    // create array of rows
    var tablerows = tables[t].rows;
    for (var r = 2; r < tablerows.length; r++)
    {
        currentRow = tablerows[r];

        // Check if current row contains map name
        if (currentRow.innerHTML.match(map_regex))
        {
            var tablecells = currentRow.cells;
            for (var c = 1; c < tablecells.length; c++)
            {
                currentCell = tablecells[c];
                // Check if current cell contains device name
                if (currentCell.innerHTML.match(device))
                {
                    document.getElementById("boxy2").innerHTML = currentCell.innerHTML;
                    flag = true;
                }
                if (flag == true) return; 
            }
            if (flag == true) return; 

            // search for x20 if 920 was not found etc
            if (device == "910")
                device = "x10";
            else if (device == "920")
                device = "x20";
            else if (device == "930")
                device = "x30";
            else if (device == "940")
                device = "x40";
            else if (device == "950")
                device = "x50";

            // search cells again
            for (var c = 1; c < tablecells.length; c++)
            {
                currentCell = tablecells[c];
                if (currentCell.innerHTML.match(device))
                {
                    document.getElementById("boxy2").innerHTML = currentCell.innerHTML;
                    flag = true;
                }
                if (flag == true) return;
            }
            if (flag == true) return;
        }
        if (flag == true) return; else  { document.getElementById("boxy2").innerHTML="Map not available on this device."; }
    }
}

}

Any help with this matter would be greatly appreciated!

  • 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-20T02:22:27+00:00Added an answer on May 20, 2026 at 2:22 am

    As you are just wanting to check for presence of a specific string, I think your solution will probably be more robust if you use indexOf rather than RegExps.

    Using RegExps, if you are looking for special characters eg [ or ] or ( or ) then you will need to escape them, this is just another layer of complexity which I don’t think you need to introduce.

    So try replacing regex usages such as…

    if (currentRow.innerHTML.match(map_regex))
    

    with this…

    if (currentRow.innerHTML.indexOf(mapString)!=-1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of C# code that add the values of an enum
I have a piece of C# code that needs to convert a string array
I have a piece of code here that i really could use some help
Let's say I have to implement a piece of T-SQL code that must return
I have a piece of code looking like this : TAxis *axis = 0;
I have this piece of code (summarized)... AnsiString working(AnsiString format,...) { va_list argptr; AnsiString
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this piece of code: var myObj = function () { this.complex =
I have a piece of code in ANSI C which uses the time.h library

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.