Home arrow JavaScript arrow Page 5 - Metacharacters, Flags and Regular Expressions in JavaScript
JAVASCRIPT

Metacharacters, Flags and Regular Expressions in JavaScript


Welcome to the fourth part of a five-part series on regular expressions in JavaScript. In this part, you'll learn about metacharacters, combining matching features, and more.

Author Info:
By: Chrysanthus Forcha
Rating:  stars stars stars stars stars / 0
July 29, 2009
TABLE OF CONTENTS:
  1. · Metacharacters, Flags and Regular Expressions in JavaScript
  2. · Metacharacters
  3. · The lastIndex Property of the Regexp Object
  4. · Regexps Flags Revisited
  5. · The m Flag

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Metacharacters, Flags and Regular Expressions in JavaScript - The m Flag
(Page 5 of 5 )

As I said in part two of the series, the m flag is not used in a straightforward manner. This is what you have in the specification about the m flag:

The m flag is used to match over multiple lines.

The m flag reflects whether or not to search in strings across multiple lines.

multiline is a property of an individual regular expression object..


The value of multiline is true if the "m" flag was used; otherwise, it is false. The "m" flag indicates that a multiline input string should be treated as multiple lines. For example, if "m" is used, "^" and "$" change from matching at only the start or end of the entire string to the start or end of any line within the string.

You cannot change this property directly.

In my opinion the specification is not clear. Well, I will not say any more about the g flag than what I have said in this section.

Combining Flags

There are three flags. You can combine them. The following code combines the i and m flags. Each test function produces a match.


<script type="text/javascript">

var availableString = "A dog is an animal. Dogs are domestic animals. There are different species of dogs";


var re = /dog/ig ;


if (re.test(availableString))

alert('Matched');

else

alert('Not Matched');

 

alert(re.lastIndex);


if (re.test(availableString))

alert('Matched');

else

alert('Not Matched');

 

alert(re.lastIndex);

</script> 

We have come to the end of this part of the series. We have also come to the end of the first phase of the series. In the next phase and last part of the series, we shall talk more about the properties and methods of the regexp object. We shall also talk about properties and methods of related string objects.

Let us take a break here, and continue in the next part.


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 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials