JSFiddle - React, Tailwind, and code Playground
by cannap
HTML
<script>
////////////////////////////////////////////////////////
// VerbalExpressions.js //
////////////////////////////////////////////////////////
// VerbalExpressions JavaScript Library v0.1.2 //
// github.com/VerbalExpressions/JSVerbalExpressions //
// //
// Released under the MIT license //
// https://opensource.org/licenses/MIT //
// //
// Date: 2013-07-19 //
////////////////////////////////////////////////////////
(function(){function t(){var i=new RegExp;return t.injectClassMethods(i),i}function i(){return new t}var e=this;t.injectClassMethods=function(i){for(var e in t.prototype)t.prototype.hasOwnProperty(e)&&(i[e]=t.prototype[e]);return i},t.prototype={_prefixes:"",_source:"",_suffixes:"",_modifiers:"gm",sanitize:function(t){return t.source?t.source:"number"==typeof t?t:t.replace(/[^\w]/g,function(t){return"\\"+t})},add:function(t){return this._source+=t||"",this.compile(this._prefixes+this._source+this._suffixes,this._modifiers),this},startOfLine:function(t){return t=t!==!1,this._prefixes=t?"^":"",this.add(""),this},endOfLine:function(t){return t=t!==!1,this._suffixes=t?"$":"",this.add(""),this},then:function(t){return t=this.sanitize(t),this.add("(?:"+t+")"),this},find:function(t){return this.then(t)},maybe:function(t){return t=this.sanitize(t),this.add("(?:"+t+")?"),this},anything:function(){return this.add("(?:.*)"),this},anythingBut:function(t){return t=this.sanitize(t),this.add("(?:[^"+t+"]*)"),this},something:function(){return this.add("(?:.+)"),this},somethingBut:function(t){return t=this.sanitize(t),this.add("(?:[^"+t+"]+)"),this},replace:function(t,i){return t=t.toString(),t.replace(this,i)},lineBreak:function(){return this.add("(?:\\r\\n|\\r|\\n)"),this},br:function(){return this.lineBreak()},tab:function(){return...
JavaScript
//Open your developer tools to see console messages.
console.clear();
////////////////////////////////////////////////////////
// Testing if we have a valid URL //
////////////////////////////////////////////////////////
console.log("");console.log("----------Testing if we have a valid URL----------")
// Create an example of how to test for correctly formed URLs
var tester = VerEx()
.startOfLine()
.then( "http" )
.maybe( "s" )
.then( "://" )
.maybe( "www." )
.anythingBut( " " )
.endOfLine();
// Create an example URL
var testMe = "https://www.google.com";
// Use RegExp object's native test() function
if( tester.test( testMe ) ) console.log( "We have a correct URL "); // This output will fire
else console.log( "The URL is incorrect" );
console.log( tester ); // Ouputs the actual expression used: /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/
////////////////////////////////////////////////////////
// Replacing Strings //
////////////////////////////////////////////////////////
console.log("");console.log("----------------Replacing Strings-----------------")
// Create a test string
var replaceMe = "Replace bird with a duck";
// Create an expression that seeks for word "bird"
var expression = VerEx().find( "bird" );
// Execute the expression like a normal RegExp object
var result = expression.replace( replaceMe, "duck" );
console.log( result ); // Outputs "Replace duck with a duck"
////////////////////////////////////////////////////////
// Shorthand for string replace //
////////////////////////////////////////////////////////
console.log("");console.log("-----------Shorthand for string replace-----------")
var result = VerEx().find( "red" ).replace( "We have a red house", "blue" );
console.log( result ); // Outputs "We have a blue house"