Weird Regex Behavior

Weird Regex Behavior

NatcheyNatchey Posts: 6Questions: 1Answers: 0
edited September 2018 in Free community support

I'm using this example because I want a pre-filtering to occur when my table loads:
https://datatables.net/reference/option/searchCols

But I have no idea what is going on with the regex behavior. I'm trying to use the OR operator in my expression. Is this true regex?

This Works:
"Analyst Progress"

This Doesn't Work:
"Analyst Progress|Review"

But this does work...:
"Analyst Progress|*" (with asterisk)

Snippet:
"searchCols": [
{ "search": "Analyst Progress|Review Progress", "regex": true},
null,
null,
null,
null
]

Using the asterisk seems to suggest the regex is working... I've also had success with a negative lookahead (^((?!Failed).)*$).

Furthermore I know my expression is good because I'm doing this same expression in column.search().draw(), this same expression works fine:
.search("(^((?!" + associatedTasks + ").)*$)", true, false)
.draw();

Any idea why this isn't working?

Hope this question makes sense.

This question has an accepted answers - jump to answer

Answers

  • NatcheyNatchey Posts: 6Questions: 1Answers: 0
    edited September 2018

    Anyone can answer this if you want. Instead of doing that for pre-filtering, I did this instead:
    $(window).on('load', function() {
    v = this.value
    table.columns(0)
    .search("Analyst Progress|Review", true, false)
    .draw();
    });

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    I took your example an put into this test case:
    http://live.datatables.net/feminipo/1/edit

    Added the option search.smart and set to false.

        "searchCols": [
          null,
          { "search": "System Architect|Director", 
           "regex": true, 
           "smart": false},
          null,
          null,
          null,
          null
        ]
    

    This seems to work. Same as your search API with regex true and smart false.

    Kevin

  • NatcheyNatchey Posts: 6Questions: 1Answers: 0

    Awesome! I was not aware I needed to explicitly set smart to false. I expected by setting regex to true it would implicitly set smart to false. Thanks for the help.

This discussion has been closed.