RegExp

Overview

The RegExp object is used for matching text with a pattern.

For more information see: RegExp (MDN).

Properties Summarized

TypeNameSummary

Specifies if the "g" modifier is set.

Specifies if the "i" modifier is set.

An integer specifying the index at which to start the next match.

Specifies if the "m" modifier is set.

The text used for pattern matching.

Methods Summarized

TypeNameSummary

Search a string for a specified value.

Search a string for a specified value.

Properties Detailed

global

Specifies if the "g" modifier is set.

Type Boolean

Sample

var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www');
application.output(patt1.global);

ignoreCase

Specifies if the "i" modifier is set.

Type Boolean

Sample

var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www');
application.output(patt1.ignoreCase);

lastIndex

An integer specifying the index at which to start the next match.

Type Number

Sample

var str = 'The rain in Spain stays mainly in the plain';
var patt1 = new RegExp('ain', 'g');
patt1.test(str);
application.output('Match found. index now at: ' + patt1.lastIndex);

multiline

Specifies if the "m" modifier is set.

Type Boolean

Sample

var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www','m');
application.output(patt1.multiline);

source

The text used for pattern matching.

Type String

Sample

var str = 'Visit www.servoy.com';
var patt1 = new RegExp('www.','g');
application.output('The regular expression is: ' + patt1.source);

Methods Detailed

exec(string)

Search a string for a specified value. Returns the found value and remembers the position.

Parameters

Returns: String A String representing the found value.

Sample

var str='Visit www.servoy.com';
var patt=new RegExp('servoy');
application.output(patt.exec(str));

test(string)

Search a string for a specified value. Returns true or false.

Parameters

Returns: Boolean true if a match was found in the string. false otherwise.

Sample

var str='Visit www.servoy.com';
var patt=new RegExp('soft');
application.output(patt.test(str)==true);
patt.compile('servoy');
application.output(patt.test(str)==true)

Last updated