regex build
Pip install fix
복잡한 한 줄의 정규식 문자열을 구축하십시오.
선호하는 건물 방법은 RegexBuild 인스턴스에 한 줄의 통화 체인을 사용하는 것입니다. 더 복잡한 경우 컨텍스트 관리자로 사용하면 동일한 인스턴스에서 여러 통화를 할 수 있습니다.
RegexBuild 의 인스턴스는 문자열과 상호 교환 적으로 사용될 수있어 여러 중첩 인스턴스를 사용할 수 있습니다.
> >> original_regex = r'.*\Roaming\(Microsoft|NVIDIA|Adobe\.*(Asset|Native)Cache)\'
# Complex example
> >> with RegexBuild ( r'.*\Roaming\' ) as build_regex :
... build_regex (
... 'Microsoft' , 'NVIDIA' , RegexBuild ( r'Adobe\.*' )( 'Asset' , 'Native' )( 'Cache' ),
... )( r'\' )
> >> original_regex == str ( build_regex )
True
# Different ways to build the same regex
> >> with RegexBuild ( '(?i)' , exit = '$' ) as case_insensitive :
... # As one line
... case_insensitive ( 'prefix1_' )( 'word1' , 'word2' )( '_suffix1' )
...
... # As context managers
... with case_insensitive ( 'prefix2_' ) as prefix :
... with prefix ( 'word2' , 'word3' ) as words :
... words ( '_suffix2' )
...
... # As context manager using the "end" parameter
... with case_insensitive ( 'prefix3_' , end = '_suffix3' ) as prefix :
... prefix ( 'word4' )
... prefix ( 'word5' )
...
> >> case_insensitive
'(?i)(prefix1_(word1|word2)_suffix1|prefix2_(word3|word4)_suffix2|prefix3_(word5|word6)_suffix3)$'