Home arrow JavaScript arrow Page 11 - Understanding the JavaScript RegExp Object

Over And Out - JavaScript

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.

TABLE OF CONTENTS:
  1. Understanding the JavaScript RegExp Object
  2. Enter the Matrix
  3. Two to Tango
  4. Game, Set, Match
  5. Search and Destroy
  6. In Splits
  7. Objects in the Rear-View Mirror
  8. One Mississippi, Two Mississippi...
  9. Changing Things Around
  10. Working with Forms
  11. Over And Out
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 144
February 09, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

After reading this tutorial, I'm pretty sure you're going to look at JavaScript in a different light. The language you just saw wasn't the one most commonly associated with image swaps and browser detection. Rather, it was a powerful tool to help you execute pattern-matching tasks in the client quickly and efficiently.

I started off with a simple introduction to regular expressions and quickly moved to the search() and replace() methods of the JavaScript String object. These functions take a regular expression as parameter and allow you to carry out smart "search-and-replace" operations on string values. This was followed by an introduction to the hero behind the scenes: the core JavaScript Regexp object. This object comes with a host of methods and properties that allow ordinary programmers to leverage off the power of regular expressions in JavaScript.

To close this article, I developed a simple example that demonstrates the use of complex regular expressions to validate form input - a routine task in all Web-based applications. If you do this often, it makes sense for you to build a good library of regular expressions for common validations (if you already have one, send me some mail and tell me all about it).

Here are some additional URLs to help you understand the concept of regular expressions further:

Stringing Things Along, at
http://www.melonfire.com/community/columns/trog/article.php?id=173

Pattern Matching and Regular Expressions, at
http://www.webreference.com/js/column5/

Regular Expressions for client-side JavaScript, a free online quick reference by VisiBone at http://www.visibone.com/regular-expressions/

That's all for this article. See you soon!

Note: Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article.



 
 
>>> More JavaScript Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVASCRIPT ARTICLES

- Javascript for Beginners: An Introduction
- Introduction to JavaScript
- Adding Elements to a Tree with TreeView jQue...
- Using the Persist Argument in a TreeView jQu...
- Using Unique and Toggle in a TreeView jQuery...
- Using Event Delegation for Mouseover Events ...
- Using the Animate Option in a Treeview jQuer...
- Using HTML Lists with Event Delegation in Ja...
- Opened and Closed Branches on a TreeView jQu...
- Mouseover Events and Event Delegation in Jav...
- Creating a TreeView JQuery Hierarchical Navi...
- Event Delegation in JavaScript
- A Look at the New YUI Carousel Control
- Working with Draggable Elements and Transpar...
- Displaying Pinned Handles with Resizable Con...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: