RegExp() : RegExp Object « Regular Expressions « JavaScript Tutorial

JavaScript Tutorial
1. Language Basics
2. Operators
3. Statement
4. Development
5. Number Data Type
6. String
7. Function
8. Global
9. Math
10. Form
11. Array
12. Date
13. Dialogs
14. Document
15. Event
16. Location
17. Navigator
18. Screen
19. Window
20. History
21. HTML Tags
22. Style
23. DOM Node
24. Drag Drop
25. Object Oriented
26. Regular Expressions
27. XML
28. GUI Components
29. Dojo toolkit
30. jQuery
31. Animation
32. MS JScript
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
JavaScript Tutorial » Regular Expressions » RegExp Object 
26. 7. 1. RegExp()

Syntax

var variable = new RegExp(pattern, flags)

The RegExp() object represents a regular expression that is used for pattern matching.

The creation of the object takes pattern and flags parameters.

The pattern is a valid regular expression. The flags are either or both g (global) and i (ignore case).

Properties and Methods of the RegExp() Object

Property/MethodDescription
RegExp.$*Represents multiline
RegExp.$&Represents lastmatch
RegExp.$_Represents input
RegExp.$`Represents leftContext
RegExp.$'Represents rightContext
RegExp.$+Represents lastParen
RegExp.$1,$2,...$9Represents substring of matches
compile()Compiles a regular expression
exec()Executes the search for a match in a specified string
global_Specifies whether to check the expressions against all possible matches
ignoreCaseWhether case is ignored or not during a string search
inputString that is matched
lastIndex_Specifies the index at which to start matching the next string.
lastMatchLast matched characters
lastParenThe last parenthesized substring match
leftContextThe substring preceding the most recent match
multilineSpecifies whether to search on multiple lines
rightContextThe substring following the most recent match
sourceThe string pattern
test()Tests for a string match


<html>
    <body>
    <script language="JavaScript">
    <!--
    function isSSN(str){
       // xxx-xx-xxxx
       var regexp = /^(\d{9}|\d{3}-\d{2}-\d{4})$/;
       return regexp.test(str);
    }
    function checkInput(){
      var valid = true;
      var ssn = document.form1.ssn.value;
      if (!isSSN (ssn)){
          window.alert("Invalid SSN: " + ssn);
          valid = false;
      }
      else{
        alert(ssn + " is a valid SSN");
      }
    }
    -->
    </script>
    <form name="form1">
    Enter your SSN:
    <input type="text" size="15" name="ssn">
    <br><br>
    <input type="button" value="Validate SSN" onClick='checkInput()'>
    <br>
    </form>
    </body>
    </html>
26. 7. RegExp Object
26. 7. 1. RegExp()
26. 7. 2. RegExp,$* (1)
26. 7. 3. RegExp.$& (2)
26. 7. 4. RegExp,$_ (3)
26. 7. 5. RegExp.$` (4)
26. 7. 6. RegExp.$' (5)
26. 7. 7. RegExp.$+ (6)
26. 7. 8. RegExp.$1,$2,..$9
26. 7. 9. RegExp.compile()
26. 7. 10. RegExp.exec()
26. 7. 11. RegExp.global
26. 7. 12. RegExp.ignoreCase
26. 7. 13. RegExp.input
26. 7. 14. RegExp.lastIndex
26. 7. 15. RegExp.lastMatch
26. 7. 16. RegExp.lastParen
26. 7. 17. RegExp.leftContext
26. 7. 18. RegExp.multiline
26. 7. 19. RegExp.rightContext
26. 7. 20. RegExp.source
26. 7. 21. RegExp.test()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.