All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jangaroo-runtime.2.0.19.source-code.RegExp.as Maven / Gradle / Ivy

There is a newer version: 4.1.8
Show newest version
package {

/**
 * The RegExp class lets you work with regular expressions, which are patterns that you can use to perform searches in strings and to replace text in strings.
 * 

You can create a new RegExp object by using the new RegExp() constructor or by assigning a RegExp literal to a variable:

* * var pattern1:RegExp = new RegExp("test-\\d", "i"); * var pattern2:RegExp = /test-\d/i; * *

For more information, see "Using Regular Expressions" in the ActionScript 3.0 Developer's Guide.

*

View the examples

* @see String#match() * @see String#replace() * @see String#search() * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * */ [Native] public dynamic class RegExp { /** * Specifies whether the dot character (.) in a regular expression pattern matches new-line characters. Use the s flag when constructing a regular expression to set dotall = true. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following example shows the effect of the s (dotall) flag on a regular expression: * * var str:String = "

Hello\n" * + "again

" * + "

Hello

"; * * var pattern:RegExp = /

.*?<\/p>/; * trace(pattern.dotall) // false * trace(pattern.exec(str)); //

Hello

* * pattern = /

.*?<\/p>/s; * trace(pattern.dotall) // true * trace(pattern.exec(str)); *

*/ public native function get dotall():Boolean; /** * Specifies whether to use extended mode for the regular expression. When a RegExp object is in extended mode, white space characters in the constructor string are ignored. This is done to allow more readable constructors. *

Use the x flag when constructing a regular expression to set extended = true.

* @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following example shows different ways to construct the same regular expression. In each, the regular expression is to match a phone number pattern of xxx-xxx-xxxx or (xxx) xxx-xxxx or (xxx)xxx-xxxx. The second regular expression uses the x flag, causing the white spaces in the string to be ignored. * * var rePhonePattern1:RegExp = /\d{3}-\d{3}-\d{4}|\(\d{3}\)\s?\d{3}-\d{4}/; * var str:String = "The phone number is (415)555-1212."; * * trace(rePhonePattern1.extended) // false * trace(rePhonePattern1.exec(str)); // (415)555-1212 * * var rePhonePattern2:RegExp = / \d{3}-\d{3}-\d{4} | \( \d{3} \) \ ? \d{3}-\d{4} /x; * trace(rePhonePattern2.extended) // true * trace(rePhonePattern2.exec(str)); // (415)555-1212 * */ public native function get extended():Boolean; /** * Specifies whether to use global matching for the regular expression. When global == true, the lastIndex property is set after a match is found. The next time a match is requested, the regular expression engine starts from the lastIndex position in the string. Use the g flag when constructing a regular expression to set global to true. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following example shows the effect setting the g (global) flag on the exec() method: * * var pattern:RegExp = /foo\d/; * var str:String = "foo1 foo2"; * trace(pattern.global); // false * trace(pattern.exec(str)); // foo1 * trace(pattern.lastIndex); // 0 * trace(pattern.exec(str)); // foo1 * * pattern = /foo\d/g; * trace(pattern.global); // true * trace(pattern.exec(str)); // foo1 * trace(pattern.lastIndex); // 4 * trace(pattern.exec(str)); // foo2 * */ public native function get global():Boolean; /** * Specifies whether the regular expression ignores case sensitivity. Use the i flag when constructing a regular expression to set ignoreCase = true. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following example shows the effect of setting the i (ignoreCase) flag: * * var pattern:RegExp = /bob/; * var str:String = "Bob bob"; * trace(pattern.ignoreCase); // false * trace(pattern.exec(str)); // bob * * pattern = /bob/i; * trace(pattern.ignoreCase); // true * trace(pattern.exec(str)); // Bob * */ public native function get ignoreCase():Boolean; /** * Specifies the index position in the string at which to start the next search. This property affects the exec() and test() methods of the RegExp class. However, the match(), replace(), and search() methods of the String class ignore the lastIndex property and start all searches from the beginning of the string. *

When the exec() or test() method finds a match and the g (global) flag is set to true for the regular expression, the method automatically sets the lastIndex property to the index position of the character after the last character in the matching substring of the last match. If the g (global) flag is set to false, the method does not set the lastIndexproperty.

*

You can set the lastIndex property to adjust the starting position in the string for regular expression matching.

* @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following example shows the effect of setting the lastIndex property, and it shows how it is updated after a call to the exec() method on a regular expression in which the g (global) flag is set: * * var pattern:RegExp = /\w\d/g; * var str:String = "a1 b2 c3 d4"; * pattern.lastIndex = 2; * trace(pattern.exec(str)); // b2 * trace(pattern.lastIndex); // 5 * trace(pattern.exec(str)); // c3 * trace(pattern.lastIndex); // 8 * trace(pattern.exec(str)); // d4 * trace(pattern.lastIndex); // 11 * trace(pattern.exec(str)); // null * */ public native function get lastIndex():Number; /** * @private */ public native function set lastIndex(value:Number):void; /** * Specifies whether the m (multiline) flag is set. If it is set, the caret (^) and dollar sign ($) in a regular expression match before and after new lines. Use the m flag when constructing a regular expression to set multiline = true. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following example shows the effect setting the m (multiline) flag: * * var pattern:RegExp = /^bob/; * var str:String = "foo\n" * + "bob"; * trace(pattern.multiline); // false * trace(pattern.exec(str)); // null * * pattern = /^bob/m; * trace(pattern.multiline); // true * trace(pattern.exec(str)); // bob * */ public native function get multiline():Boolean; /** * Specifies the pattern portion of the regular expression. * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea7.html Flags and properties * * @example The following code outputs the source parameter for two regular expressions: * * var re1:RegExp = /aabb/gi; * trace (re1.source); // aabb * * var re2:RegExp = new RegExp("x+y*", "i"); * trace(re2.source); // x+y* * */ public native function get source():String; /** * Lets you construct a regular expression from two strings. One string defines the pattern of the regular expression, and the other defines the flags used in the regular expression. * @param re The pattern of the regular expression (also known as the constructor string). This is the main part of the regular expression (the part that goes within the "/" characters). *

Notes:

*
    *
  • Do not include the starting and trailing "/" characters; use these only when defining a regular expression literal without using the constructor. For example, the following two regular expressions are equivalent: * * var re1:RegExp = new RegExp("bob", "i"); * var re2:RegExp = /bob/i;
  • *
  • In a regular expression that is defined with the RegExp() constructor method, to use a metasequence that begins with the backslash (\) character, such as \d (which matches any digit), type the backslash character twice. For example, the following two regular expressions are equivalent: * * var re1:RegExp = new RegExp("\\d+", ""); * var re2:RegExp = /\d/; *

    In the first expression, you must type the backlash character twice in this case, because the first parameter of the RegExp() constructor method is a string, and in a string literal you must type a backslash character twice to have it recognized as a single backslash character.

* @param flags The modifiers of the regular expression. These can include the following: *
    *
  • g ? When using the replace() method of the String class, specify this modifier to replace all matches, rather than only the first one. This modifier corresponds to the global property of the RegExp instance.
  • *
  • i ? The regular expression is evaluated without case sensitivity. This modifier corresponds to the ignoreCase property of the RegExp instance.
  • *
  • s ? The dot (.) character matches new-line characters. Note This modifier corresponds to the dotall property of the RegExp instance.
  • *
  • m ? The caret (^) character and dollar sign ($) match before and after new-line characters. This modifier corresponds to the multiline property of the RegExp instance.
  • *
  • x ? White space characters in the re string are ignored, so that you can write more readable constructors. This modifier corresponds to the extended property of the RegExp instance.
*

All other characters in the flags string are ignored.

* * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea9.html Regular expression syntax * */ public native function RegExp(re:String = null, flags:String = null); /** * Performs a search for the regular expression on the given string str. *

If the g (global) flag is not set for the regular expression, then the search starts at the beginning of the string (at index position 0); the search ignores the lastIndex property of the regular expression.

*

If the g (global) flag is set for the regular expression, then the search starts at the index position specified by the lastIndex property of the regular expression. If the search matches a substring, the lastIndex property changes to match the position of the end of the match.

* @param str The string to search. * * @return If there is no match, null; otherwise, an object with the following properties: *
    *
  • An array, in which element 0 contains the complete matching substring, and other elements of the array (1 through n) contain substrings that match parenthetical groups in the regular expression
  • *
  • index ? The character position of the matched substring within the string
  • *
  • input ? The string (str)
* * @see String#match() * @see String#search() * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea8.html Methods for using regular expressions with strings * * @example When the g (global) flag is not set in the regular expression, then you can use exec() to find the first match in the string: * * var myPattern:RegExp = /(\w*)sh(\w*)/ig; * var str:String = "She sells seashells by the seashore"; * var result:Object = myPattern.exec(str); * trace(result); * *

The result object is set to the following:

*
    *
  • result[0] is set to "She" (the complete match).
  • *
  • result[1] is set to an empty string (the first matching parenthetical group).
  • *
  • result[2] is set to "e" (the second matching parenthetical group).
  • *
  • result.index is set to 0.
  • *
  • result.input is set to the input string: "She sells seashells by the seashore".
*

In the following example, the g (global) flag is set in the regular expression, so you can use exec() repeatedly to find multiple matches:

* * var myPattern:RegExp = /(\w*)sh(\w*)/ig; * var str:String = "She sells seashells by the seashore"; * var result:Object = myPattern.exec(str); * * while (result != null) { * trace ( result.index, "\t", result); * result = myPattern.exec(str); * } * *

This code results in the following output:

*
           0      She,,e
   10     seashells,sea,ells
   27     seashore,sea,ore
   
*/ public native function exec(str:String):Array; /** * Tests for the match of the regular expression in the given string str. *

If the g (global) flag is not set for the regular expression, then the search starts at the beginning of the string (at index position 0); the search ignores the lastIndex property of the regular expression.

*

If the g (global) flag is set for the regular expression, then the search starts at the index position specified by the lastIndex property of the regular expression. If the search matches a substring, the lastIndex property changes to match the position of the end of the match.

* @param str The string to test. * * @return If there is a match, true; otherwise, false. * * @see http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ea8.html Methods for using regular expressions with strings * * @example The following example shows the use of the test() method on a regular expression in which the g (global) flag is set: * * var re1:RegExp = /\w/g; * var str:String = "a b c"; * trace (re1.lastIndex); // 0 * trace (re1.test(str)); // true * trace (re1.lastIndex); // 1 * trace (re1.test(str)); // true * trace (re1.lastIndex); // 3 * trace (re1.test(str)); // true * trace (re1.lastIndex); // 5 * trace (re1.test(str)); // false * */ public native function test(str:String):Boolean; public native function get index():Number; public native static function get leftContext():String; public native static function get input():String; public native static function get lastParen():String; public native static function get lastMatch():String; public native static function get rightContext():String; public native function get $1():String; public native function get $2():String; public native function get $3():String; public native function get $4():String; public native function get $5():String; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy