Using Smart and Regex and searching
Using Smart and Regex and searching
barrykeepence
Posts: 22Questions: 0Answers: 0
I wanted to search with regex and look for multiple matching elements so I turned on smart search.
The problem with smart search is that it splits strings on spaces so if I wanted to search for a string with spaces it would split it.
I changed the function to this:
[code]
function _fnFilterCreateSearch( sSearch, bRegex, bSmart, bCaseInsensitive )
{
var asSearch, sRegExpString;
if ( bSmart )
{
/* Generate the regular expression to use. Something along the lines of:
* ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
*/
asSearch = bRegex ? sSearch.match( /\w+|"[^"]+"/g ) : _fnEscapeRegex( sSearch ).split( ' ' );
if ( asSearch ) {
for (var i=0;i
The problem with smart search is that it splits strings on spaces so if I wanted to search for a string with spaces it would split it.
I changed the function to this:
[code]
function _fnFilterCreateSearch( sSearch, bRegex, bSmart, bCaseInsensitive )
{
var asSearch, sRegExpString;
if ( bSmart )
{
/* Generate the regular expression to use. Something along the lines of:
* ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$
*/
asSearch = bRegex ? sSearch.match( /\w+|"[^"]+"/g ) : _fnEscapeRegex( sSearch ).split( ' ' );
if ( asSearch ) {
for (var i=0;i
This discussion has been closed.
Replies
Having said tat, if this is a feature required often enough (this is the first request) I will look at adding that ability.
Regards,
Allan
My users can understand simple regex but not advanced regex. I was using the non-regex and smart filtering for my users and they complained about not being able to enter search strings (e.g. in quotes).
The problem with smart filtering is that it will always split on a space even if it is in quotes.
How about just changing smart filtering to not split on spaces in between quotes?
> The problem with smart filtering is that it will always split on a space even if it is in quotes
In needs to do that split in order to do the smart filtering (i.e. individual word, regardless of its position in the string).
Changing it to not split between quotes sounds like a decent idea, although currently it searches for the quotes as well, so it would be a change in behaviour. Possibly a good one though - that's an ability I use in Google quite a lot myself.
Allan
Good feature suggestion :-)
Allan