Bobert1234 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
for the mongodb driver, it seems i have to use the qr// format of regular expressions.
from the documentation, :
The problem is that i have to create the query by reading existing mongo regex strings, e.g.Use qr/.../ to use a regular expression in a query ..... my $cursor = $collection->query({"name" => qr/[Jj]oh?n/});
i tried changing this through basic string manipulation to prepend the qr :{"name" => '/.*uba$/i'}
but i think it's just treating that as a string for full matching instead of applying it is a regex. it's certainly not working. i also tried (after prepending the qr) passing it to a function and creating a qr object:{"name" => 'qr/.*uba$/i'}
but that outputs:if(index($_[0],"qr/") >= 0){ $_[0] =~s/qr(.*?)(i?)$/$1/s; print $fh Dumper($_[0]); if($2=='i'){ my $re = qr/$_[0]/i; }else{ my $re = qr/$_[0]/; } $_[0] =$re; print $fh Dumper($_[0]); }
I'm very new to perl, so it's very possible that i'm missing something obvious. any ideas?$VAR1 = '/.*uba$/'; $VAR1 = undef;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: creating qr from existing regex
by Perlbotics (Archbishop) on Feb 08, 2018 at 18:13 UTC | |
by Bobert1234 (Novice) on Feb 08, 2018 at 18:26 UTC | |
by poj (Abbot) on Feb 08, 2018 at 19:08 UTC | |
by Bobert1234 (Novice) on Feb 09, 2018 at 06:54 UTC | |
by AnomalousMonk (Archbishop) on Feb 09, 2018 at 14:47 UTC | |
by Your Mother (Archbishop) on Feb 09, 2018 at 18:30 UTC | |
Re: creating qr from existing regex
by vr (Curate) on Feb 09, 2018 at 11:15 UTC | |
Re: creating qr from existing regex
by bart (Canon) on Feb 09, 2018 at 18:18 UTC | |
by AnomalousMonk (Archbishop) on Feb 09, 2018 at 21:07 UTC | |
by bart (Canon) on Feb 12, 2018 at 11:47 UTC |
Back to
Seekers of Perl Wisdom