Regular Expressions in JavaScript

This is an example of using a JavaScript Regular Expression in WordPress.

Type some text below, or use some sample text.

Type a Regular Expression below.

Below is the JavaScript for reference. Notice that jQuery is used to get the input from the form and set the output text.

<script type="text/javascript">
function testRegEx()
{
var $j = jQuery.noConflict();
var textString = $j("input[name=usertext]").val();
var regexString = $j("input[name=regex]").val();
var regex = new RegExp(regexString);
var matchString = regex.exec(textString);
$j("input[name=match]").val(matchString);
}
</script>