The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.
The Flash and PHP Bible has a forum for quick support.
Match content in Javascript using Regular Expressions.
The topic of regular expressions can be advanced, but this article will drill down to a specific use
The problem is, you have a link <a href="">Link Me</a> which you want to match just the "Link Me" portion.
<script type="text/javascript">
<!--
var haystack = '<a href="test">Link Me</a>';
var regexPattern = new RegExp(/^<.*>(.*)<\/.*>$/i);
var matches = new Array();
matches = haystack.match(regexPattern);
window.onload = function()
{
matches.splice(0, 1);
alert(matches;
}
//-->
</script>
As you can see, the meat of this code is within the new RegExp() call.
The actual matching pattern is:
/^<.*>(.*)<\/.*>$/i
This example is called once the page loads and after the match is completed, simply alerts (outputs) the matches in the form of a dialog box.
The "match()" function is called from the string and takes the regular expression pattern as an argument.
Once the pattern array is filled you want to remove the first entry, because it contains the complete matched pattern. This is achieved using splice() function on the newly created array.
matches.splice(0, 1);
That is all there is to this basic regular expression matching system
The next step will be to form this into a complete tool and even port it to ActionScript, now that AS3 offers native regular expression support.
Follow Scriptplayground on Twitter (@scriptplay)
©2004 - 2012 scriptplayground | Privacy Policy | Legal
Validate Site: XHTML CSS | Designed by: Matthew Keefe of mkeefeDESIGN