Quantcast
Viewing latest article 3
Browse Latest Browse All 4

Answer by nu11p01n73R for Finding the contents of parenthesis

Use search instead of match

for test in tests:...     m = re.search ("\(d.(.*)\)", test)...     if m:...         print(m.groups())... (' October 9, 1999',)(' December 28, 1991',)

Why match wont work?

Tha match searches the pattern at the start of the string. In the test string, the matched part is not at the start of the string and hence match fails. Where as search searches for the pattern anywhere in the string.

  • re.search(pattern, string, flags=0)

    Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding MatchObject instance. Return None if no position in the string matches the pattern;


Viewing latest article 3
Browse Latest Browse All 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>