现在我有这个正则表达式:
/regular(\[[a-z]*\])* expression/i
正确匹配此字符串:
Regular[AECC][XVK] Expression
但未能与这些匹配:
R[AECC]egular [XVK]Expression
R[ABC]egular Expression
Regular[xx] Expressio[]n
如何将以上所有与单个正则表达式匹配?
答案 0 :(得分:3)
/
r (?:\[[a-z]*\])?
e (?:\[[a-z]*\])?
g (?:\[[a-z]*\])?
...
i (?:\[[a-z]*\])?
o (?:\[[a-z]*\])?
n
/ix
或
my $pat = join '(?:\\[[a-z]*\\])?', map quotemeta, split //, 'regular expression';
my $re = qr/$pat/i;
/$re/
或
s/\[[a-z]*\]//ig;
/regular expression/i