How to set ignorecase flag for part of regular expression in Python?

后端 未结 3 1511
臣服心动
臣服心动 2020-12-19 07:54

Is it possible to implement in Python something like this simple one:

#!/usr/bin/perl
my $a = \'Use HELLO1 code\';
if($a =~ /(?i:use)\\s+([A-Z0-9]+)\\s+(?i:c         


        
3条回答
  •  天涯浪人
    2020-12-19 08:23

    According to the docs, this is not possible. The (?x) syntax only allows you to modify a flag for the whole expression. Therefore, you must split this into three regexp and apply them one after the other or do the "ignore case" manually: /[uU][sS][eE]...

提交回复
热议问题