JavaScript sql_regcase
Make regular expression for case insensitive match
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 18 19 2021 22 23 24 25 | function sql_regcase (str) { // Make regular expression for case insensitive match // // version: 1008.1718 // discuss at: http://phpjs.org/functions/sql_regcase // + original by: Brett Zamir (http://brett-zamir.me) // - depends on: setlocale // * example 1: sql_regcase('Foo - bar.'); // * returns 1: '[Ff][Oo][Oo] - [Bb][Aa][Rr].' this.setlocale('LC_ALL', 0); var i=0, upper = '', lower='', pos=0, retStr=''; upper = this.php_js.locales[this.php_js.localeCategories.LC_CTYPE].LC_CTYPE.upper; lower = this.php_js.locales[this.php_js.localeCategories.LC_CTYPE].LC_CTYPE.lower; for (i=0; i < str.length; i++) { if (((pos = upper.indexOf(str.charAt(i))) !== -1) || ((pos = lower.indexOf(str.charAt(i))) !== -1)) { retStr += '['+upper.charAt(pos)+lower.charAt(pos)+']'; } else { retStr += str.charAt(i); } } return retStr; } |
Examples
Running
1 | sql_regcase('Foo - bar.'); |
Should return
1 | '[Ff][Oo][Oo] - [Bb][Aa][Rr].' |
Dependencies
In order to use this function, you also need:
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have sql_regcase goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: @HalfWinter, Paulo Freitas, Andros Peña Romo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>