|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis handy utility program tests JavaScript Regular Expressions in a browser using JavaScript. Its interface is similar to other regular expression test tools, but unlike those tools, it tests JavaScript's implementation of Regular Expression in JavaScript. BackgroundI often find myself writing JavaScript code for both the client side and server side that uses Regular Expressions for parsing text or validating input. However, as Regular Expressions can often get very complex, I needed a reliable tool to be able to test the expressions that I would write to make sure that I got the expected results. While there were many Regular Expression test tools, none were written specifically to test Regular Expressions as implemented in JavaScript. So I copied what I liked from the interfaces of some of these tools and wrote my own in HTML and JavaScript. This makes it perfect for testing JavaScript Regular Expressions as it's written with JavaScript and executed in JavaScript. I share this code for several reasons. First is to let other people find it and use it. I think that it is useful, and I think that you may find it useful as well. I have used this with very large blocks of text, that is greater than one megabyte, and found it to be reasonably fast for a test environment. I also want to hear feedback about it, what is useful, what is good, and which parts suck -- but only if you tell how you think it could be improved. As I am not currently writing many complex regular expressions any more, I don't have the reason to use this tool as hard. I would like to hear from people who can, and are, using it. Using the codeType in the regular expression at the top and the text on which the regular expression is to work in the bottom left. Press the "match" button. Other options include replacing the matched text (use $1, $2 etc. for back references). There a few options which JavaScript allows one to use, and I have exposed as much of these as I could. The regular expression can be written in text format, i.e., The technical detailsAll of the data is stored in a JavaScript object called " This interface uses frames, and so each frame need to be able to communicate what its "state" is to the To get the data from the frames into the object, every event in each form element copies the data to the top level function copyDown() {
document.local.TheText.value = window.top.RegExTest.theText;
};
function copyUp() {
window.top.RegExTest.theText = document.local.TheText.value;
};
You can think of the // Walk through all of the frames starting at the very top level, which this is
function CopyUp() {
if (top.frames.length) {
CopyUpFrames(top.frames);
};
};
// Walks through all of the frames starting at the very top level
function CopyUpFrames(theFrame) {
for (i=0;i<theFrame.length;I++)
// Call copyUp() in each page of the frameset
if (theFrame[i].copyUp) {
theFrame[i].copyUp();
};
// if the page contains frames, walk through those too
if (theFrame[i].frames.length) {
CopyUpFrames(theFrame[i].frames);
};
};
};
The File Contents
Naughty or NiceI know that many people don't like Still to be doneReplacement with strings, even with back references, works great. But I have not yet implemented the feature to do a replacement with a function, so it is currently a disabled feature in the interface, and is otherwise ignored. HistoryVersion 1.00.150 published 2004-10-20.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||