【问题标题】:Search in sqlite table where column matches regex在列与正则表达式匹配的 sqlite 表中搜索
【发布时间】:2010-12-28 18:13:39
【问题描述】:

我正在 Rails 中编写一个使用 sqlite 的 Web 应用程序。我希望用户能够使用正则表达式搜索数据库中的表。这可能吗?谢谢。

【问题讨论】:

    标签: sql ruby-on-rails regex sqlite


    【解决方案1】:

    是的,有一个regexp operator.。但是你必须实现这个功能。

    【讨论】:

      【解决方案2】:

      这是我用来实现 REGEX 函数的代码(使用 PHP 和 PDO):

      #to implement regex searches
      function php_regex_match ($regex, $str) {
          if (preg_match("/$regex/", $str, $matches)) {
           return 1; #$matches[0];
          }
       return false;
      }
      $db->sqliteCreateFunction('REGEXP', 'php_regex_match', 2);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-01-17
        • 1970-01-01
        • 2016-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-25
        相关资源
        最近更新 更多