C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Using Regular Expression in JavaScript


Posted Date: 20 Jun 2008    Resource Type: Code Snippets    Category: Javascript
Author: Kapil DhawanMember Level: Gold    
Rating: Points: 5



RegExp is a Regular Expression object in Java Script. RegExp object is useful to search texts in a texts.

The RegExp object contains three member functions:


  1. test()

  2. exec(), and

  3. compile()



The test () method searches a string for with a specified value. It either returns true or false.


var testPattern=new RegExp("kapil");
document.write(testPattern.test("I am kapil dhawan")); //returns true


The exec () method searches a string for a specified value. But, unlike test (), it returns the text of the value found. When no match is found, it returns null.


var execPattern=new RegExp("kapil");
document.write(execPattern.exec("I am kapil Dhawan")); //returns 'kapil'


The compile () method is used to change the RegExp.


var compPattern=new RegExp("kapil");
document.write(compPattern.test("I am kapil dhawan"));//returns true


The other case in this example might be


compPattern.compile("dhawan");
document.write(compPattern.test("I am kapil dhawan")); //returns true


Regular expressions are really powerful in optimizing searches for texts. When used, it obviates the need for a method that has to read the text from the beginning instead of searching for patterns.














Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Regular expressions  .  Regular expression for text search  .  Regex objects in javascript  .  Regex objects  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Popup Boxes in Javascript
Previous Resource: Declaring Variables in JavaScript
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use