I have an html page with small javascript function embedded inside script tags. I am writing another javascript/jquery function inside the same page to load this page as text in a variable and search for the code inside the smaller javascript function.
Example: This is my file: abc.html. The search should ideally return alert(element).
<!DOCTYPE html>
<html>
<body>
<button id="btn-get">$.get()</button>
<script data-require="jquery" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script type="text/javascript" charset="utf-8">
function getValue(element)
{
alert(element);
//end
}
var content, matched;
$('#btn-get').click(function(e)
{
$.get('abc.html', function(data)
{
content = data;
});
matched = String(content).match("getValue(.*)end");
console.log(matched);
});
</script>
</body>
</html>
This returns (.*) from the search query, which is not what I want. I have tried the suggestions in the following SO posts:
Regex get all content between two characters
Find string between two strings in Javascript or jQuery
regex search a string for contents between two strings
They return null value. I tried using split, pop as well. Nothing works for this case. Can this be done? What would be the best way to get the correct output? Thanks in advance!