Regular Expression in Global Search: ending string character not working

Regular Expression in Global Search: ending string character not working

martafernandezmartafernandez Posts: 5Questions: 2Answers: 0
edited January 2023 in Free community support

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

  • martafernandezmartafernandez Posts: 5Questions: 2Answers: 0

    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.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    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

Sign In or Register to comment.