Custom REGEXP Function to be used in a SQLITE SELECT Statement

前端 未结 2 478
离开以前
离开以前 2020-12-19 18:58

I have an SQLITE Database\'s File which in one of the table columns there is some simple Regular Expressions.

These Expressions are something like /foo(.

相关标签:
2条回答
  • 2020-12-19 19:11

    Is this what you are looking for?

    e.g. SELECT * FROM `my_table` WHERE `my_column` REGEXP "\/foo(.?)"
    
    0 讨论(0)
  • 2020-12-19 19:14

    You can use SQLiteDatabase::createFunction documentation here or PDO::sqliteCreateFunction documentation here

    I did something like this:

    <?php
    function _sqliteRegexp($string, $pattern) {
        if(preg_match('/^'.$pattern.'$/i', $string)) {
            return true;
        }
        return false;
    }
    $PDO->sqliteCreateFunction('regexp', '_sqliteRegexp', 2);
    ?>
    

    Use:

    SELECT route FROM routes WHERE pattern REGEXP 'your/url/string' LIMIT 1
    
    0 讨论(0)
提交回复
热议问题