HomeJavaScript Understanding the JavaScript RegExp Object
Understanding the JavaScript RegExp Object
Need to match and replace patterns on a Web page? You don't need Perl or PHP - JavaScript can do the job just as well. In this article, find out how, with an introduction to the JavaScript RegExp object and its methods. After reading this tutorial, I'm pretty sure you're going to look at JavaScript in a different light. The language ins't the one most commonly associated with image swaps and browser detection, but it serves as a powerful tool to help you execute pattern-matching tasks in the client quickly and efficiently.
Most Real Programmers treat JavaScript like the poor cousin from the country - useful in certain situations, but not very important. Real Programmers aren't interested in a language whose primary application seems to be swapping one image with another, or drawing mouse trails across a Web page. Real Programmers have better things to do.
Well, all you Real Programmers out there better hang on to your hats - JavaScript may only be confined to the client side of a Web transaction, but in that territory, it's the undisputed king. No other language is so easy to learn, or allows you to do quite so many things with minimum fuss. And one of the things it lets you do - quite well - is use regular expressions in your code.
Over the course of this article, I'm going to give you a gentle introduction to the concept of regular expressions in the context of JavaScript. I'll be showing you how to use JavaScript's String object for basic string matching and replacing capabilities, as well as more complex string manipulation. And I'll introduce you to the RegExp object, which provides a handy way to create more efficient code for common client-side input validation. So come on in; regardless of whether you're a Real Programmer or just trying to be one, you're sure to find something useful inside.