Why does the regex pattern not match the code?
Do you have any idea why this regex does not match the code below?
$regex = "!<title>(.*?)</title>!i";
code:
<b:include data='blog' name='all-head-content'/>
<title>
<b:if cond='data:blog.homepageUrl == data:blog.url'>
<data:blog.title/>
<b:else/>
<data:blog.pageName/> » <data:blog.title/>
</b:if>
</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesh开发者_Python百科eet' type='text/css'/>
Don't use regular expressions to parse XML.
Your expression doesn't work because the dot doesn't match new lines. Adding the DOTALL modifier /.../s
would fix that, but then you'll have other problems like matching greedily instead of lazy.
Using an XML parser would be a better idea.
Here is my suggestion for a correct regex:
(?<=<title>)(.*)(?=</title>)
精彩评论