<HTML>
<Head>
<Title> regular expression test page </title>
<! --- Some styles to make the page look nice --->
<Style>
Body {font-family: Arial; font-size: 12px}
Input {font-size: 11px}
Textarea {font-size: 11px}
Th {Background: # 8888ff; color: White; text-align: Left}
TD {Background: # cccc99; color: black; font-size: 12px}
TD. ROWA {Background: # cccc99}
TD. rowb {Background: # eeeebb}
. Header {font-weight: bold}
</Style>
<Script language = "JavaScript">
// Turn off fields used only by replace
Function hidereplacefields (){
Document. getelementbyid ('regexreplicase'). Disabled = true;
Document. getelementbyid ('replace header'). Disabled = true;
}
// Turn on fields used only by replace
Function showreplacefields (){
Document. getelementbyid ('regexreplicase'). Disabled = false;
Document. getelementbyid ('replace header'). Disabled = false;
}
// Perform a find
Function processregexfind (text, RegEx, flags ){
VaR Reg = new Regexp (RegEx, flags );
VaR lastidx =-1;
VaR icount = 0;
VaR result = "";
VaR output = '<Div style = "height: 200px; overflow-Y: auto; width: 550">' +
'<Table border = "0" cellpadding = "2" cellspacing = "0" width = "550">' +
'<Tr> <TH width = "*"> match </Th> <TH width = "50"> position </Th> <TH width = "50"> length </Th> </tr> ';
// Loop as long as have matches
While (lastidx! = 0)
{
// Do it
VaR mtch = reg.exe C (text );
// Check if got one
If (Reg. lastindex! = 0)
{
// Yep, increment counter
Icount ++;
If (icount % 2)
Style = "ROWA ";
Else
Style = "rowb ";
// Write output
Output + = '<tr class = "' + style + '"> <TD>' +
Regexp. lastmatch + "</TD> <TD>" +
(Reg. lastIndex-RegExp.lastMatch.length) + "</TD> <TD>" +
Regexp. lastmatch. Length + "</TD> </tr> ";
}
Lastidx = reg. lastindex;
}
Output + = "</table> ";
// Build result
If (icount! = 0)
Result = "matches found:" + icount + "<br>" + output;
Else
Result = "no matches ";
Return result;
}
// Process a replace
Function processregexreplace (text, regexfind, regexreplace, flags ){
// Define RegEx
VaR Re = new Regexp (regexfind, flags );
// Do it
VaR newstr = text. Replace (Re, regexreplace );
// Generate output
VaR result = '<Div style = "height: 200px; overflow-Y: auto; width: 550">' +
'<Table border = "0" cellpadding = "2" cellspacing = "0" width = "550">' +
'<Tr> <TH> new text </Th> </tr> <TD>' +
Newstr + '</TD> </tr> ';
Return result;
}
// Process entry point
Function processregex (form ){
VaR output = "";
VaR flags;
If (Form. casesensitive. Checked)
Flags = "G ";
Else
Flags = "Gi ";
// What to do?
If (Form. operationfind. Checked ){
Output = processregexfind (Form. searchtext. Value, form. RegEx. Value, flags );
}
Else if (Form. operationreplace. Checked ){
Output = processregexreplace (Form. searchtext. Value, form. RegEx. Value, form. regexreplace. Value, flags );
}
Document. getelementbyid ('output'). innerhtml = output;
Return false;
}
</SCRIPT>
</Head>
<Body>
<Form name = "tester" Action = "" method = "Post" onsubmit = "processregex (this); Return false">
<Table border = "1" cellpadding = "4" cellspacing = "0" width = "550">
<Tr>
<TH class = "dialog"> Regular Expression tester </Th>
</Tr>
<Tr>
<TD class = "dialog">
<! --- Text input for the regular expression itself --->
<SPAN class = "Header"> enter a regular expression: </span> <br>
<Input name = "RegEx" type = "text" size = "65" style = "font-size: 13px">
<! --- Checkbox to control case-sensiti.pdf --->
<Input type = "checkbox" name = "casesensitive" id = "casesensitive" value = "yes">
<Label for = "casesensitive"> case sensitive </label>
<Br>
<! --- Radio buttons to display find vs. Replace --->
<Input type = "radio" name = "operation" id = "operationfind" value = "find" Checked onclick = "hidereplacefields ()">
<Label for = "operationfind"> Find </label>
<Input type = "radio" name = "operation" id = "operationreplace" value = "replace" onclick = "showreplacefields ()">
<Label for = "operationreplace"> replace </label>
<Br>
<! --- Text input for the replace regular expression --->
<SPAN class = "Header" id = "replaceheader"> enter the replace regular expression: </span> <br>
<Input id = "regexreplace" name = "regexreplace" type = "text" size = "65" style = "font-size: 13px">
<Br>
<! --- Textarea where user can type the text to Search --->
<SPAN class = "Header"> and the text you wish to search: </span> <br>
<Textarea name = "searchtext" Wrap = "off" Cols = "70" rows = "6"> </textarea>
<Br>
<! --- Submit button to start the search --->
<Input name = "Submit" type = "Submit" style = "font-weight: bold" value = "match now"> </TD>
</Tr>
</Table>
</Form>
<! -- Display any reults here --->
<Span id = "output"> </span>
<! -- Default to find --->
<Script language = "JavaScript">
Hidereplacefields ();
</SCRIPT>
</Body>
</Html>