Item1975: Adding match operator =~ in queries

Priority: Enhancement
Current State: Closed
Released In: 1.1.0
Target Release: minor
Applies To: Engine
Reported By: MichaelDaum
Waiting For:
Last Change By: KennethLavrsen
... for %IF and %SEARCH ...

The code below implements a
operator following the notation from DBCacheContrib. This one is different from
which is more of a glob match.

When these operators a translated to SQL, the match operator will most probably be limited to POSIX 1003.2 Extended Regular Expressions as DBs don't have the full power of perl regexes at hand.

Not sure if there is a way to force a regex to be interpreted POSIXish in perl as that does not make much sense normally.

package Foswiki::Query::OP_match;

use strict;

use Foswiki::Query::BinaryOP ();
our @ISA = ('Foswiki::Query::BinaryOP');

sub new {
    my $class = shift;
    return $class->SUPER::new( name => '=~', prec => 500 );

sub evaluate {
    my $this = shift;
    my $node = shift;
    return $this->evalTest(
        sub {
            defined( $_[0] ) && defined( $_[1] )
              && $_[0] =~ m/$_[1]/s ? 1 : 0;


Michael and I have been discussing this offline, and are agreed that support for POSIX regexes is an excellent enhancement. Confirmed.

Regarding POSIX compliance, see

-- CrawfordCurrie - 26 Aug 2009

What was the feature proposal topic for this old one?

I do not remember seeing a feature proposal for this, but I could just be short of memory.

I scanned through the accepted feature proposals and I cannot see one that match from the headlines.

-- KennethLavrsen - 25 Mar 2010

how the *? can you claim to be waiting for release when you have broken the unit tests for Fn_IF ?

-- SvenDowideit - 26 Mar 2010

Can't find feature proposal either. Creating one: AddMatchOperatorToQueryLanguage

I am fine reverting the code immediately. However, it makes sense to have the code in the core discussing the related bug in the Infix::Parser.

-- MichaelDaum - 26 Mar 2010

Rationalised support for escaped chars in constant strings; moved unit tests to QueryTests.

-- CrawfordCurrie - 26 Mar 2010
Topic revision: r21 - 04 Oct 2010, KennethLavrsen
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy