<!DOCTYPE html PUBLIC "- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Javascript Regular Expression Exec()</title>
<script type="text/javascript">
var strText = "\
I like big butts and I can not lie \
You other brothers can't deny \
That when a girl walks in with an itty bitty waist \
And a round thing in your face \
You get sprung \
Wanna pull up tough \
Cuz you notice that butt was stuffed \
Deep in the jeans she's wearing \
I'm hooked and I can't stop staring \
Oh, baby I wanna get with ya \
And take your picture \
";
var rePattern = new RegExp(
"(big|round|bitty)(?:\\s+)([^\\s]+)",
"gi"
);
</script>
</head>
<body>
<script type="text/javascript">
var arrMatch = null;
while (arrMatch = rePattern.exec( strText )){
document.write(
arrMatch[ 1 ].toUpperCase() +
" modifies " +
arrMatch[ 2 ].toUpperCase() +
"<br />"
);
document.write(
"........ " +
"Phrase: " +
arrMatch[ 0 ] +
"<br />"
);
document.write(
"........ " +
"Start Index: " +
arrMatch.index +
"<br />"
);
document.write (
"........ " +
"End Index: " +
rePattern.lastIndex +
"<br />"
);
document.write (
"........ " +
"Index Substring: " +
arrMatch.input.substring(
arrMatch.index,
rePattern.lastIndex
) +
"<br /><br />"
);
}
</script>
</body>
</html>