how do i group the title tags in regular expression....
I need the same same title tags as per the requirement
If regular expressions are grouped something like this; how do i just replace part 2 and keep the rest of the regular expression as is...
r'(<title>)(.+?)(</title>)'
\1 \2 \3
My answer should be like this...
blah<title>Bar title</title>second title<title>Bar title</title>blah
The function must:
1. Return a new string, where the content found between <title> and
</title> (*case insensitive*) are replaced with the function's TITLE argument.
All other text should remain unchanged, including the <title> opening and
closing tags. All occurances of <title> tags should be rewritten, if there is
more than 1.
2. The function documentation should read:
Replace the HTML title contents with the given TITLE
I need the same same title tags as per the requirement
If regular expressions are grouped something like this; how do i just replace part 2 and keep the rest of the regular expression as is...
r'(<title>)(.+?)(</title>)'
\1 \2 \3
My answer should be like this...
blah<title>Bar title</title>second title<title>Bar title</title>blah
The function must:
1. Return a new string, where the content found between <title> and
</title> (*case insensitive*) are replaced with the function's TITLE argument.
All other text should remain unchanged, including the <title> opening and
closing tags. All occurances of <title> tags should be rewritten, if there is
more than 1.
2. The function documentation should read:
Replace the HTML title contents with the given TITLE
def rewrite_title(hb,nt): """ Replace the HTML title contents with the given TITLE """ rhb = re.sub(r'<title>(.+?)</title>', nt,0 re.IGNORECASE) print rhb hb = 'blah<title>{title}</title>second title<title>{newtitle}</title>blah' nt = 'Bar title' print rewrite_title(hb,nt)