wildstring

I needed a wildcard processing tool for an application I was working on.  I didn't want to use regular expressions, because the wildcard values were going in a configuration file, and regex would basically render them unreadable.  So I looked around for a wildcard library for JS and couldn't find a decent one.  In fact, when people asked for one, they generally were told "Learn Regular Expressions".  While I completely agree that knowledge of regular expressions is an incredible boon to a programming career, my response to a problem is not to tell someone it can't be solved, so I wrote a library of may own

Introducing wildstring

wildstring does simple wildcard processing without any dependencies.  It works both on the client and in the server, so you can use it anywhere.  wildstring handles wildcard string processing simply.  Here are some examples

wildstring.match('Wild*', 'Wild Thing'); // returns true, because ' Thing' is matched by '*'
wildstring.replace('You make my heart *', 'string'); // returns 'You make my heart string' because * is replaced with string
wildstring.replace('You * everything *', [ 'make', 'groovy' ]); // returns 'You make everything groovy' because 'make' replaces the first * and 'groovy' replaces the second

It can also accept alternative wildcards.
wildstring.wildcard = '||';
wildstring.match("I || you", "I think I love you"); // true
wildstring.replace("You make my heart ||", "string"); // "You make my heart string"
And you can tell wildstring to ignore case when matching
wildstring.caseSensitive = false;
wildstring.match("Wild *", "wILD tHING"); // true

Comments

Popular Posts