Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript regex returning null but it shouldn't be. Why?
    text
    copied!<p>I have a regex that searches the source of a page it retrieves via Ajax and gets all the data inbetween and including the fieldset tags.</p> <p>Here's my javascript:</p> <pre><code> var req = new XMLHttpRequest(); var regex = new RegExp("&lt;(fieldset)\b[^&gt;]*&gt;.*?&lt;/\1&gt;"); function showEditForm(i) { req.open('GET', '/admin/maps/edit/' + i, false); req.send(null); var response = req.responseText; //strip out all the line breaks var responseStripped = response.replace( new RegExp("\\n|\\r", "g"), "" ); var regexed = regex.exec(responseStripped) alert(regexed); } </code></pre> <p>Here's the source of responseStripped:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;&lt;head&gt; &lt;meta http-equiv="content-type" content="text/html;charset=UTF-8" /&gt; &lt;title&gt;Gessner Engineering | Administrative Area | edit&lt;/title&gt; &lt;link href="/stylesheets/scaffold.css?1236625014" media="screen" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt;&lt;body&gt; &lt;div id="user-bar-greeting"&gt;Logged in as Thomas Gessner&lt;/div&gt; &lt;div id="user-bar-action" &gt;(&lt;a href="/logout" title="Log out"&gt;Log out&lt;/a&gt;)&lt;/div&gt;&lt;div id="header"&gt;&lt;/div&gt;&lt;ul id="menu"&gt; &lt;li&gt;&lt;a href="/admin"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/admin/maps"&gt;Geotechnical Map&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/admin/profiles"&gt;Profiles&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/admin/projects"&gt;Projects&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/admin/users"&gt;Users&lt;/a&gt;&lt;/li&gt;&lt;/div&gt;&lt;div id="content"&gt; &lt;h1&gt;&lt;/h1&gt; &lt;fieldset&gt;&lt;legend&gt;Edit Test Marker&lt;/legend&gt;&lt;form action="/admin/maps/1" class="edit_map" enctype="multipart/form-data" id="edit_map_1" method="post"&gt;&lt;div style="margin:0;padding:0"&gt;&lt;input name="authenticity_token" type="hidden" value="1422cd87ff4d68b2b23c9015a0568bffd47fbfeb" /&gt;&lt;/div&gt; &lt;p&gt; &lt;label for="map_name"&gt;Name&lt;/label&gt;&lt;br /&gt; &lt;input id="map_name" name="map[name]" size="30" type="text" value="Test Marker" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="map_description"&gt;Description&lt;/label&gt;&lt;br /&gt; &lt;textarea cols="40" id="map_description" name="map[description]" rows="5"&gt;test&lt;/textarea&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="category_id"&gt;Category:&lt;/label&gt;&lt;br/&gt; &lt;select id="map_category_id" name="map[category_id]"&gt;&lt;option value=""&gt;Select One&lt;/option&gt;&lt;/select&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="map_address"&gt;Address&lt;/label&gt;&lt;br /&gt; &lt;input id="map_address" name="map[address]" size="30" type="text" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="map_address2"&gt;Address2&lt;/label&gt;&lt;br /&gt; &lt;input id="map_address2" name="map[address2]" size="30" type="text" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="map_city"&gt;City&lt;/label&gt;&lt;br /&gt; &lt;input id="map_city" name="map[city]" size="30" type="text" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="map_state"&gt;State&lt;/label&gt;&lt;br /&gt; &lt;input id="map_state" name="map[state]" size="2" type="text" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="map_zip"&gt;Zip&lt;/label&gt;&lt;br /&gt; &lt;input id="map_zip" name="map[zip]" size="30" type="text" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input id="map_submit" name="commit" type="submit" value="Create" /&gt; &lt;/p&gt;&lt;/form&gt;&lt;/fieldset&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>I've verified that the regex works in RegexBuddy and at <a href="http://regexpal.com" rel="nofollow noreferrer">RegexPal</a>.</p> <p>However, when all is said and done, I get null returned.</p> <p>What am I doing wrong?</p> <p>Thanks!</p> <p><em>Please note this is in testing form, it may look ugly but I tried to break it down step by step and this is the last state it was in.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload