regexp_opt - Convert list of strings to a regular expression


use List::Regexp qw(:all);

my $s = regexp_opt(@strings);

my $s = regexp_opt(\%opts, @strings);


Returns a regular expression that will match any string from the input list @strings. First argument can be a reference to a hash, which controls how the regexp is built.

Valid keys are:

type => pcre|posix|emacs

Controls the flavor of the generated expression: Perl-compatible (the default), POSIX extended, or Emacs.

match => default|exact|word

If default, the expression will match any word from @strings appearing as a part of another word.

If exact, the expression will match a word from @strings appearing on a line alone.

If word, the expression will match single words only.

debug => 0|1

If 1, enable debugging output.

group => 0|1

If 1, enclose entire regexp in a group.


GPLv3+: GNU GPL version 3 or later, see <>

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.


Sergey Poznyakoff <>