Skip to content
jehna edited this page Jul 21, 2013 · 2 revisions

Description: Add a alternative expression to be matched.

Example: The following will test if the string begins with http://, https:// or ftp://.

var link = 'ftp://ftp.google.com/';
var expression = VerEx()
                 .find( "http" )
                 .maybe( "s" )
                 .then( "://" )
                 .or()
                 .then( "ftp://" )
if( expression.test( link ) ) alert( "We have a link" ); // This alert will fire

/* variable "expression" will output:
/((http)(s)?(\:\/\/))|((ftp\:\/\/))/gm
*/

Example: The .or() method creates always new chain, so if we wanted to optimize the previous example, we could use two different expressions.

var link = 'ftp://ftp.google.com/';
var expression = VerEx()
                 .find(
                    VerEx()
                    .find( "http" )
                    .maybe( "s" )
                    .or( "ftp" )
                 )
                 .then( "://" )
if( expression.test( link ) ) alert( "We have a link" ); // This alert will fire

/* variable "expression" will output:
/(((http)(s)?)|((ftp)))(\:\/\/)/gm
*/

.or( value )

Description: Add a alternative expression to be matched

Parameter Description
String value The string to be looked for

Example: The following will replace all articles with the word "the"

var my_paragraph = 'Then a quick brown fox jumps over an excited dog';
my_paragraph = VerEx().find( "a " ).or( "an " ).replace( my_paragraph, "the " );
/* Outputs:
Then the quick brown fox jumps over the excited dog
*/
Clone this wiki locally