Home arrow JavaScript arrow Page 5 - Case and Negation in JavaScript Regular Expressions
JAVASCRIPT

Case and Negation in JavaScript Regular Expressions


Welcome to the third part of a five-part series that examines the use of regular expressions in JavaScript. In this part, we'll look at the effects of case sensitivity, how to use negation, and more.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
July 22, 2009
TABLE OF CONTENTS:
  1. · Case and Negation in JavaScript Regular Expressions
  2. · Abbreviations for Common Character Classes
  3. · Beginning and Ending a String
  4. · Matching Repetitions
  5. · Matching the Whole String

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Case and Negation in JavaScript Regular Expressions - Matching the Whole String
(Page 5 of 5 )

You can match the whole available string, using the '^' with the '$' characters. The following code produces a match:

 

/^be.*end$/.test("beginning and end")

 

The following code also produces a match:

 

/^be.*end$/.test("beginning with end")

 

The available string of the first case is "beginning and end." The available string of the next case is "beginning with end." The difference occurs in the word in the middle.

The regexp content of both cases is the same. The content begins with '^' and ends with '$'. The regexp indicates that the available string to be matched has to begin with "de," followed by any character, any number of times; and the available string has to end with "end."

The period stands for any character. The '*' following the period in the regexp means that any character can reoccur in sequence. So '.*' in regexp tells it to match any character any number of times (including zero times).

Note: all along, when we say match, we are actually searching the available string for a sub-string, represented by the content of the regexp. However, when you are matching the whole available string, the regexp represents the whole string.

So you can now match a whole string. By the time you complete this series, you will be able to match an entire available string that has particular words within the string. I will not show you how to do that. It will be an exercise for you. You will simply need to combine many of the techniques I explain in this series.

We will take a break here and continue in the next part of the series.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials