NAME String::Query::To::Regexp - Convert query to regular expression VERSION This document describes version 0.003 of String::Query::To::Regexp (from Perl distribution String-Query-To-Regexp), released on 2022-11-02. SYNOPSIS use String::Query::To::Regexp qw(query2re); my $re; $re = query2re("foo"); # => qr/\A(?=.*foo).*\z/s -> string must contain 'foo' $re = query2re({ci=>1}, "foo"; # => qr/\A(?=.*foo).*\z/is -> string must contain 'foo', case-insensitively $re = query2re("foo", "bar"); # => qr/\A(?=.*foo)(?=.*bar).*\z/s -> string must contain 'foo' and 'bar', order does not matter $re = query2re("foo", "-bar"); # => qr/\A(?=.*foo)(?!.*bar).*\z/s -> string must contain 'foo' but must not contain 'bar' $re = query2re({bool=>"or"}, "foo", "bar"); # => qr/\A(?:(?=.*foo)|(?!.*bar)).*\z/s -> string must contain 'foo' or 'bar' $re = query2re({word=>1}, "foo", "bar"); # => qr/\A(?=.*\bfoo\b)(?!.*\bbar\b).*\z/s -> string must contain words 'foo' and 'bar'; 'food' or 'lumbar' won't match $re = query2re({re=>1}, "foo", "/bar+/", qr/baz/i); # => qr/(?^s:\A(?=.*foo\+)(?=.*(?^i:bar+))(?=.*(?^u:baz+)).*\z)/ -> allow regexes in queries DESCRIPTION This module provides "query2re" function to convert one or more string queries to a regular expression. Features of the queries: * Negative searching using the *-FOO* syntax FUNCTIONS query2re Usage: my $re = query2re([ \%opts , ] @query); Create a regular expression object from query @query. Known options: * bool Str. Default "and". Either "and" or "or". * word Bool. Default false. If set to true, queries must be separate words. * ci Bool. Default false. If set to true, will do case-insensitive matching * re Bool. Default false. If set to true, will allow regexes in @query as well as converting string queries of the form "/foo/" to regex using Regexp::From::String. HOMEPAGE Please visit the project's homepage at <https://metacpan.org/release/String-Query-To-Regexp>. SOURCE Source repository is at <https://github.com/perlancar/perl-String-Query-To-Regexp>. SEE ALSO AUTHOR perlancar <perlancar@cpan.org> CONTRIBUTING To contribute, you can send patches by email/via RT, or send pull requests on GitHub. Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via: % prove -l If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me. COPYRIGHT AND LICENSE This software is copyright (c) 2022 by perlancar <perlancar@cpan.org>. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGS Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=String-Query-To-Regex p> When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.