如何在带引号的正则(qr)表达式中添加修饰符 [英] How to add a modifier to a quoted regular (qr) expression
本文介绍了如何在带引号的正则(qr)表达式中添加修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法可以将正则表达式修饰符(例如"i")添加到带引号的正则表达式中?例如:
Is there an easy way to add regex modifiers such as 'i' to a quoted regular expression? For example:
$pat = qr/F(o+)B(a+)r/;
$newpat = $pat . 'i'; # This doesn't work
我唯一想到的方法是转到print "$pat\n"
并返回(?-xism:F(o+)B(a+)r)
,并尝试用替换项删除?-xism:
中的'i'
The only way I can think of is to print "$pat\n"
and get back (?-xism:F(o+)B(a+)r)
and try to remove the 'i' in ?-xism:
with a substitution
推荐答案
您不能将标志放在已经具有的qr
结果中,因为它受到了保护.而是使用此:
You cannot put the flag inside the result of qr
that you already have, because it’s protected. Instead, use this:
$pat = qr/F(o+)B(a+)r/i;
这篇关于如何在带引号的正则(qr)表达式中添加修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文