Created
April 23, 2018 16:17
-
-
Save theredpea/69295fd011551a3d1e1c34fc80f6420e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.factory('smartRegExp', [function(){ | |
return { | |
get : function(searchTerm){ | |
searchTerm = searchTerm || ''; | |
var quoteMatch = searchTerm.match(/^"(.*)"$/); | |
var regExp; | |
if (quoteMatch) { | |
//This supports DataTable "full string matching" in its smart search | |
//Only match what is between the leading and trailing ", match in its entirety: | |
regExp = new RegExp(quoteMatch[1] | |
.toLowerCase(), 'gi'); | |
} else { | |
// Replacing the data table https://datatables.net/reference/option/search.smart | |
// https://stackoverflow.com/a/23452217/1175496 | |
// Build Regexp with logicial OR; any series of whitespaces | |
//Adding | |
regExp = new RegExp(searchTerm | |
.toLowerCase() | |
.replace(/\s+/g, "|") | |
//Replace double quotes ; assume they haven't yet finished a quoteMatch with a trailing double-quote; | |
//Doubtful sheet names ever contain a double-quote character; they're not looking for it: | |
.replace(/\"/g, ''), 'gi'); | |
} | |
return regExp; | |
} | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment