Javascript search issue
<p>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.</p>

<p>The problem I am having is this :</p>

<p>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 "<code>Western &amp; Central"</code> to <code>"Western &amp;amp; Central"</code> but unfortunately the code is still unable to locate the phrase.</p>

<p>Heres the code:</p>

<pre><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 &lt;strong&gt; tags to map string so it is easier to search for
var mapstring = "&lt;strong&gt;" + map;
var map_regex = new RegExp( mapstring,'i');

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

for (var t = 2; t &lt; tables.length; t++)
{
    // create array of rows
    var tablerows = tables[t].rows;
    for (var r = 2; r &lt; 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 &lt; 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 &lt; 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."; }
    }
}
</code></pre>

<p>}</p>

<p>Any help with this matter would be greatly appreciated!</p>
