-
Notifications
You must be signed in to change notification settings - Fork 144
.maybe( value )
jehna edited this page Jul 21, 2013
·
5 revisions
Description: Add a string to the expression that might appear once (or not).
Parameter | Description |
---|---|
String value | The string to be looked for |
Example: The following matches all strings that begin with http://
or https://
and converts them to HTML links.
var my_paragraph = "Take a look at the link http://google.com and the secured version https://www.google.com";
var expression = VerEx()
.find( "http" )
.maybe( "s" )
.then( "://" )
.anythingBut( " " );
my_paragraph = expression.replace( my_paragraph, function(link) {
return "<a href='"+link+"'>"+link+"</a>";
} );
/* Outputs:
Take a look at the link <a href='http://google.com'>http://google.com</a> and the secured version <a href='https://www.google.com'>https://www.google.com</a>
*/