Regexp::SQL::LIKE - Translate SQL LIKE pattern to a regular expression
version 0.001
use Regexp::SQL::LIKE 'to_regexp'; my $re = to_regexp( "Hello %" ); # returns qr/^Hello .*/
This module converts an SQL LIKE pattern to its Perl regular expression equivalent.
Currently, only % and . wildcards are supported and only \ is supported as an escape character.
%
.
\
No functions are exported by default. You may rename a function on import as follows:
use Regexp::SQL::Like to_regexp => { -as => 'regexp_from_like' };
See Sub::Exporter for more details on import customization.
my $re = to_regexp( "Hello %" );
This function converts an SQL LIKE pattern into an equivalent regular expression. A % character matches any number of characters like .* and a . character matchs a single character. Backspaces may be used to escape %, . and \ itself:
.*
to_regexp( "Match literal \%" );
All other characters are run through quotemeta() to sanitize them.
quotemeta()
The function returns a compiled regular expression.
Please report any bugs or feature requests by email to bug-regexp-sql-like at rt.cpan.org, or through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Regexp-SQL-LIKE. You will be automatically notified of any progress on the request by the system.
bug-regexp-sql-like at rt.cpan.org
This is open source software. The code repository is available for public review and contribution under the terms of the license.
http://github.com/dagolden/regexp-sql-like
git clone http://github.com/dagolden/regexp-sql-like
David Golden <dagolden@cpan.org>
This software is Copyright (c) 2011 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
To install Regexp::SQL::LIKE, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Regexp::SQL::LIKE
CPAN shell
perl -MCPAN -e shell install Regexp::SQL::LIKE
For more information on module installation, please visit the detailed CPAN module installation guide.