User Tools

Site Tools


RegExp

ECMAScript RegExp prototype object.

More...

Inherits :

Properties

Constructors

ECMAScript
RegExp ( String expression, String flags=“” )

Methods

ECMAScript
Arrayexec ( String string )
Booleantest ( String string )
StringtoString ()
DAZ Script
Stringcap ( Number which )
BooleanexactMatch ( String text )
Numberpos ( Number which )
Numbersearch ( String text )
NumbersearchRev ( String text )

Detailed Description

This is the DAZScript counterpart to the QRegExp type used in the DAZ Studio SDK.

A RegExp object is a regular expression. Regular expressions are patterns used to perform searches in, or replace text in, strings.

Regular expressions can be created in DAZScript directly, or via the constructor. The following example shows creating expressions via the two methods, both of which result in identical expressions.

Recommended Reading:

Example:

var regxPair1 = /([A-Z]+)=(\d+)/;
var regxPair2 = new RegExp( "([A-Z]+)=(\\d+)" );

Properties


Boolean : global

Used to indicate that the RegExp should be matched globally. A global RegExp will match every occurrence (as many times as possible), whereas a non-global RegExp will match only once at most (the first match it encounters). This is particularly relevant for String::replace() where every occurrence of a pattern will be replaced when global is true. This is true when the pattern flags contain the character “g”.


Boolean : ignoreCase

Used to indicate that the RegExp ignores case when matching. This is true when the pattern flags contain the character “i”. (Read Only)


Number : lastIndex

The string position at which to start the next match.


Boolean : multiline

Used to indicate that the RegExp matches across multiple lines. This is true when the pattern flags contain the character “m”. (Read Only)


String : source

A string value representing the pattern source.


Array : capturedTexts

Provides an array of all the captured strings from the previous match. undefined if there was no match. (Read Only)


Boolean : empty

true if the expression is empty, otherwise false. (Read Only)


Number : matchedLength

Holds the length of the last matched string. -1 if there was no match. (Read Only)


Boolean : valid

true if the expression is syntactically valid, otherwise false. (Read Only)

Constructors


RegExp( String expression, String flags=“” )

Default constructor.

Parameter(s):

  • expression - The string representing the expression syntax.
  • flags - One of “g” (global), “i” (ignoreCase), or “m” (multiline), or a combination thereof, used to modify how the expression is applied.

Attention:

  • All backslashes in expression must be escaped with an additional backslash.

Methods


Array : exec( String string )

Performs a regular expression match on the given string.

Return Value:

  • An array of results for the match, or undefined if no matches were found.

Boolean : test( String string )

Performs a regular expression match on the given string.

Return Value:

  • true if one or more matches was found, otherwise false.

String : toString()

Return Value:

  • The regular expression pattern as a String.

String : cap( Number which )

Parameter(s):

  • which - The index of the capture to return.

Return Value:

  • The capture at the given index of the pattern in the previously matched text.

Boolean : exactMatch( String text )

Parameter(s):

  • text - The String to search with the expression pattern.

Return Value:

  • true if text exactly matches this expression's pattern, otherwise false.

Number : pos( Number which )

Parameter(s):

  • which - The index of the capture to return.

Return Value:

  • The position of the capture at the given index of the pattern in the previously matched text.

Number : search( String text )

Parameter(s):

  • text - The String to search with the expression pattern.

Return Value:

  • The [zero-based] index of the first occurrence of this expression's pattern in text, starting at the beginning of text. If no match is made -1 is returned.

Number : searchRev( String text )

Parameter(s):

  • text - The String to search with the expression pattern.

Return Value:

  • The [zero-based] index of the first occurrence of this expression's pattern in text, starting at the end of text. If no match is made -1 is returned.