www.webdeveloper.com
Results 1 to 3 of 3

Thread: regex object

  1. #1
    Join Date
    Apr 2008
    Posts
    84

    regex object

    Code:
    <script type="text/javascript">
     
    var str="Hello world!";
     //look for "Hello"
     var patt=/Hello/g;
     var result=patt.test(str);
     document.write("Returned value: " + result);  
    </script>
    when var patt is cretaed as shown above, how does it create an object of RegExp type ? To create an object of a particular type, its required to be created as "var patt=new RegExp(pattern,modifiers);" If we just specify "var patt=/Hello/g;" how will script understand that its of RegExp type only and nothing else ?

    Thanks

  2. #2
    Join Date
    Nov 2011
    Location
    Nigeria
    Posts
    28
    It is the literal syntax of the regex object, just as we have string literal, number literal, object literal and such.

  3. #3
    Join Date
    Nov 2011
    Location
    Nigeria
    Posts
    28

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles