Results 1 to 5 of 5

Thread: What is RegExp Modifiers in JavaScript?

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    What is RegExp Modifiers in JavaScript?

    I have done some basic programs in JavaScript. But I am confused when I have to use the RegExp in coding. Can someone explain me what is the RegExp and why it is used for.?? I have used it twice but I don't know the exact purpose of that.! Also later I came to know about the RegExp Modifiers. So please explain me, what is the RegExp Modifiers in JavaScript? It will be more appreciable if somebody can give me some coding regarding the same.!!
    Technology is a way of organizing the universe so that man doesn't have to experience it.-- Max Frisch 1911 -1991

  2. #2
    Join Date
    Mar 2008
    Posts
    672

    Re: What is RegExp Modifiers in JavaScript?

    The RegExp stands for the regular expression. A regular expression is written in the form of modifiers or the pattern. Here the modifiers are a series of characters indicating various options, while the pattern is the regular expression itself. While the the modifiers part is an optional. The following modifiers are supported by the JavaScript :
    1. /i makes the regexp match case insensitive.
    2. /g enables global matching.
    3. /m enables multi-line mode.

    If you want to combine multiple modifiers by stringing them together, you can do that by using the /regex/gim.

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: What is RegExp Modifiers in JavaScript?

    I think that you should know about the regular expression, before you start the RegExp Modifiers. A regular expression is an object that describes a pattern of characters. You can use a pattern to describe what you are searching for when you search in a text. A simple pattern can be one single character whereas more complicated pattern can consist of more characters and that are used for doing the parsing, format checking, substitution, etc. For doing the powerful pattern-matching and search-and-replace functions on text, regular expressions are used. Below is the syntax for the same :
    Code:
    var txt=new RegExp(pattern,modifiers);
    
    or more simply:
    
    var txt=/pattern/modifiers;
    In above example, modifiers specify if a search should be global, case-sensitive, etc. and the pattern specifies the pattern of an expression.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: What is RegExp Modifiers in JavaScript?

    The RegExp Modifiers are used to perform case-insensitive and global searches. In which there are i and g modifier. If you want to perform case-insensitive matching, then you will have to use i modifier. And if you want to perform a global match then you will have to use the g modifier. In the following example, I have tried to explain you how to use the i modifier for case-insensitive.
    Do a case-insensitive search for "lessons" in a string :
    Code:
    var str="Learn Lessons";
    var patt1=/lessons/i;
    The underlined text below shows where the expression gets a match :
    Code:
    Learn Lessons
    Signatures reduce available bandwidth

  5. #5
    Join Date
    Aug 2006
    Posts
    227

    Re: What is RegExp Modifiers in JavaScript?

    Give can glance at the following example to know how to use the g modifier.
    Do a global search for "as":
    Code:
    var str="Assure me as soon as possible";
    var patt1=/is/g;
    The output of the above RegExp Modifiers will be :
    Code:
    Assure me as soon as possible
    The underlined text shows where the expression gets a match.

    If you do the global, case-insensitive search for the above same example,
    Code:
    var str="Assure me as soon as possible";
    var patt1=/is/gi;
    The output will be like this :
    Code:
    Assure me as soon as possible
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

Similar Threads

  1. Bullet damage and player health modifiers in HomeFront
    By arjun rantu in forum Video Games
    Replies: 5
    Last Post: 16-03-2011, 10:23 PM
  2. public, private, protected access modifiers in OOP
    By Bol-Bacchan in forum Software Development
    Replies: 5
    Last Post: 09-03-2011, 05:43 PM
  3. JavaScript: RegExp and Boolean Object
    By Ivann in forum Software Development
    Replies: 5
    Last Post: 18-12-2009, 03:36 AM
  4. What is Regexp count
    By GunFighter in forum Software Development
    Replies: 3
    Last Post: 06-08-2009, 02:21 PM
  5. What are the different types of access modifiers in JAVA?
    By Bhim in forum Software Development
    Replies: 4
    Last Post: 25-02-2009, 09:53 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,318,831.71359 seconds with 17 queries