python - How to find characters not in parentheses -


attempting find occurrences of characters

string1 = '%(example_1).40s-%(example-2)_-%(example3)s_' 

so output has occurrences of '-' '_' not in parentheses

['-', '_', '-', '_'] 

do not need care nested parentheses

the following give output.:

>>> import re >>> str = '%(example_1).40s-%(example-2)_-%(example3)s_' >>> print list("".join(re.findall("[-_]+(?![^(]*\))", str))) ['-', '_', '-', '_'] 

what finds substrings containing '-' and/or '_' in str , not in parentheses. since these substrings, such matching characters joining, , splitting list.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

html - How to custom Bootstrap grid height? -