Regex and server-side processing not really working

Regex and server-side processing not really working

bacalovbacalov Posts: 22Questions: 3Answers: 0

Hello,
I have a column filled with numerical values and could not get any valid response when searching using regular expressions.
For example: this one is working excellent when searching for '3', but returning as well all the rows containing '3' (like '33', '36', '39')

var select = $('SELECT_OPTIONS')
.appendTo( $(this).empty() ).on( 'change', function () {table.column( idx ).search( $(this).val(), true, false ).draw();});

so instead I want to use a simple regex like

var select = $('SELECT_OPTIONS')
.appendTo( $(this).empty() ).on( 'change', function () {table.column( idx ).search( '^' + $(this).val() + '$', true, false ).draw();});

Data is send correctly to the server, no errors in console.

May be somebody had a similar situation or issue.

Thank you.

This question has an accepted answers - jump to answer

Answers

  • bacalovbacalov Posts: 22Questions: 3Answers: 0

    Anyone please...

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    If you want exact matching, just remove the LIKE %% in the code since that is what is doing the partial matching (assuming you are using the provided PHP libraries).

    Allan

  • bacalovbacalov Posts: 22Questions: 3Answers: 0

    Thank you, Allan for pointing to the right direction.
    I'm using provided PHP libraries, but I need a partial match as well, so... this one is working just fine:

    if ( $search && $column['search']['regex'] == 'true' ) {
    $query->where( $this->_ssp_field( $http, $i ), $search, 'REGEXP' );
    }else{
    $query->where( $this->_ssp_field( $http, $i ), '%'.$search.'%', 'like' );
    }

This discussion has been closed.