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

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -