You should use re.MatchObject.group(0)
. Like
imtag = re.match(r'<img.*?>', line).group(0)
Edit:
You also might be better off doing something like
imgtag = re.match(r'<img.*?>',line)
if imtag:
print("yo it's a {}".format(imgtag.group(0)))
to eliminate all the None
s.
More Related Contents:
- How t extract last part of a text in python [duplicate]
- re.findall behaves weird
- Do regular expressions from the re module support word boundaries (\b)?
- Python extract pattern matches
- Split a string by spaces — preserving quoted substrings — in Python
- Does “\d” in regex mean a digit?
- Remove all special characters, punctuation and spaces from string
- Use Python’s string.replace vs re.sub
- Natural sorting
- Python regular expression re.match, why this code does not work? [duplicate]
- matching any character including newlines in a Python regex subexpression, not globally
- Python, remove all non-alphabet chars from string
- Python Regex to find a string in double quotes within a string
- Python regex, matching pattern over multiple lines.. why isn’t this working?
- BeautifulSoup returns empty list when searching by compound class names
- What does the “r” in pythons re.compile(r’ pattern flags’) mean?
- Python regex to match dates
- regexes: How to access multiple matches of a group? [duplicate]
- Do Python regular expressions have an equivalent to Ruby’s atomic grouping?
- Finding words after keyword in python [duplicate]
- Grep and Python
- Regexp to remove specific number of occurrences of character only
- re.search() only matches the first occurrence
- How to get the first word in the string
- Python: UserWarning: This pattern has match groups. To actually get the groups, use str.extract
- Generate a String that matches a RegEx in Python [duplicate]
- Split string at commas except when in bracket environment
- Using ^ to match beginning of line in Python regex
- How to split long regular expression rules to multiple lines in Python
- Python regular expression not matching