I want to do something (more than just substitution) with substrings matching the pattern in a longer string. If the assignment was an expression returning a value, as in C and most other programming languages, this would be (using C syntax with Python semantics):
while ( match = re.search( pat, str ) ) { }
or in more detail, avoiding the use of assignment as an expression:
for ( match = re.search( pat, str ); match; match = re.search( pat, str ) ) { }
At least one of them is possible in most programming languages: C, C ++, Java, Perl, Javascript, ... but none of them is possible in Python. Is there a pythonic equivalent (non-messy kludgey with break or continue statement)?
source share