* Build a regular expression object suitable for searching a table * @param {string} sSearch string to search for * @param {bool} bRegex treat as a regular expression or not * @param {bool} bSmart perform smart filtering or not * @param {bool} bCaseInsensitive Do case insensitive matchin
(search, inOpts)
| 4176 | * @memberof DataTable#oApi |
| 4177 | */ |
| 4178 | function _fnFilterCreateSearch(search, inOpts) { |
| 4179 | var not = [] |
| 4180 | var options = $.extend( |
| 4181 | {}, |
| 4182 | { |
| 4183 | boundary: false, |
| 4184 | caseInsensitive: true, |
| 4185 | exact: false, |
| 4186 | regex: false, |
| 4187 | smart: true |
| 4188 | }, |
| 4189 | inOpts |
| 4190 | ) |
| 4191 | |
| 4192 | if (typeof search !== "string") { |
| 4193 | search = search.toString() |
| 4194 | } |
| 4195 | |
| 4196 | // Remove diacritics if normalize is set up to do so |
| 4197 | search = _normalize(search) |
| 4198 | |
| 4199 | if (options.exact) { |
| 4200 | return new RegExp("^" + _fnEscapeRegex(search) + "$", options.caseInsensitive ? "i" : "") |
| 4201 | } |
| 4202 | |
| 4203 | search = options.regex ? search : _fnEscapeRegex(search) |
| 4204 | |
| 4205 | if (options.smart) { |
| 4206 | /* For smart filtering we want to allow the search to work regardless of |
| 4207 | * word order. We also want double quoted text to be preserved, so word |
| 4208 | * order is important - a la google. And a negative look around for |
| 4209 | * finding rows which don't contain a given string. |
| 4210 | * |
| 4211 | * So this is the sort of thing we want to generate: |
| 4212 | * |
| 4213 | * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$ |
| 4214 | */ |
| 4215 | var parts = search.match(/!?["\u201C][^"\u201D]+["\u201D]|[^ ]+/g) || [""] |
| 4216 | var a = parts.map(function (word) { |
| 4217 | var negative = false |
| 4218 | var m |
| 4219 | |
| 4220 | // Determine if it is a "does not include" |
| 4221 | if (word.charAt(0) === "!") { |
| 4222 | negative = true |
| 4223 | word = word.substring(1) |
| 4224 | } |
| 4225 | |
| 4226 | // Strip the quotes from around matched phrases |
| 4227 | if (word.charAt(0) === '"') { |
| 4228 | m = word.match(/^"(.*)"$/) |
| 4229 | word = m ? m[1] : word |
| 4230 | } else if (word.charAt(0) === "\u201C") { |
| 4231 | // Smart quote match (iPhone users) |
| 4232 | m = word.match(/^\u201C(.*)\u201D$/) |
| 4233 | word = m ? m[1] : word |
| 4234 | } |
| 4235 |