Hello,

I am trying to create a filter criteria for a view using regular expression but it seams that it is not working.

For example I want to check if Nid is odd or even number. To achieve that I can use regular expression '[02468]$' to check if Nid ends with even number.

If I select from DB following statement it returns 1 - so it is correct

SELECT 26 REGEXP '[02468]$'

But if I create a filter criteria as a 'Regular expression" and pass value '[02468]$' (I have tried with and without quotes), then view does not return any value.

In some views I get following error

SQLSTATE[42000]: Syntax error or access violation: 1139 Got error 'empty (sub)expression' from regexp

Could you please explain what I am doing wrong?
Or is this really a bug?

I am using
Drupal 7.17 with XAMPP v3.1.0

DB server: 5.5.27 - MySQL Community Server (GPL)
Web server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
phpMyAdmin: 3.5.2.2

Thanks In Advance,
Alvis

Comments

Priority:Normal» Major

Same problem.

Could you please post the full query generated by views? I could imagine that this gives some needed context.

Currently the resultant query is appending empty string which is a mere syntax error, see the where clause below

SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created
FROM
{node} node
WHERE (( (node.nid RLIKE '', '', '[02468]$') ))

whereas WHERE (( (node.nid RLIKE '[02468]$') )) resolves the issue

This is the required changes

<?php
--- views/handlers/views_handler_filter_numeric.inc
+++ views/handlers/views_handler_filter_numeric.inc
@@ -258,7 +258,7 @@ class views_handler_filter_numeric exten
  
}
   function
op_regex($field) {
-   
$this->query->add_where($this->options['group'], $field, $this->value, 'RLIKE');
+    
$this->query->add_where($this->options['group'], $field, $this->value['value'], 'RLIKE');
   }
   function
admin_summary() {
?>

Also the same for "views/handlers/views_handler_filter_string.inc" .