The output of my re.search
returns <_sre.SRE_Match object at 0x10d6ed4e0>
I was wondering how could I convert this to a string? or a more readable form?
Both return the first match of a substring found in the string, but re. match() searches only from the beginning of the string and return match object if found. But if a match of substring is found somewhere in the middle of the string, it returns none.
match() function of re in Python will search the regular expression pattern and return the first occurrence. The Python RegEx Match method checks for a match only at the beginning of the string. So, if a match is found in the first line, it returns the match object.
How do you get the actual strings that match the pattern from a Match object? The group() method returns strings of the matched text.
You should do it as:
result = re.search(your_stuff_here) if result: print result.group(0)
If you want to see all groups in order:
result = re.search(your_stuff_here) if result: print result.groups()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With