qr-operator

How to add a modifier to a quoted regular (qr) expression

谁说我不能喝 提交于 2019-12-06 01:59:48
问题 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 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 回答1: 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; 回答2: You can modify an existing regex as if it