Regular Expression in Global Search: ending string character not working
Regular Expression in Global Search: ending string character not working
Link to test case: https://datatables.net/examples/api/regex.html
Description of problem: Testing the behaviour of regular expressions in search()
, I have noticed that the end of string character '$' does not work as expected when used in global search.
Searching ^bruno nash$
with "Treat as a RegEx" checked and "Smart search" not checked in global search returns no results, while searching for the same and same options in column - Name does return the entry.
Searching for ^bruno nash
in global search does return the entry.
Not a question exactly, but I don't know where I should start the discussion.
This question has an accepted answers - jump to answer
Answers
ADDITION:
After further testing, I think I have come to understand global search under the hood:
If you add starting or ending Regex operators "^" and "$", they only work in column 0 and last column respectively. I assume the entire row is concatenated and then the regular expression match applied.
Exactly that! This is done for performance reasons - we build a cached string for each row that can be searched, which is much quicker than having a loop over each column for each row. The big disadvantage of this approach is what you've found - regex doesn't work quite as expected.
The concatenation of the data from the cells is separated by a double space, so you could search for that. Or if you want proper and complete control over the search you can use a search plug-in.
Allan