Products
GG网络技术分享 2025-03-18 16:15 0
What\'s wrong with this regex to exclude content of title tag?
$plaintext = preg_match(\'#<title>(.*?)</title>#\', $html);
$html has html code of entire page.
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议此正则表达式排除标题标签内容有什么问题? </ p>
$ plaintext = preg_match(\'#&lt; title&gt;(。*?)&lt; / title&gt;#\',$ html); </ code> </ pre>
$ html包含整页的html代码。</ p>
</ div>
网友观点:
It sounds like you never got a working answer. Let\'s remove the title tags.
Search: (?s)<title>.*?</title>
Replace: \\\"\\\"
Code:
$regex = \\\"~(?s)<title>.*?</title>~\\\";$ replaced = preg_replace($regex,\\\"\\\",$pagecontent);
Explain Regex
(?s) # set flags for this block (with . matching#
) (case-sensitive) (with ^ and $
# matching normally) (matching whitespace
# and # normally)
<title> # \'<title>\'
.*? # any character (0 or more times (matching
# the least amount possible))
</title> # \'</title>\'
I suppose it should be like this instead...This only gives you content in between
preg_match(\'(?<=<title>).*(?=<\\/title>)\', $html);
http://www.phpliveregex.com/p/1SJ
http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
This will get everything between the two tags
preg_match(\'<title>.+\', $html);
常见的50道正则表达式题目(建议收藏)
声明:文章来源微信公众号:转行学数据分析。如需转载必须保留此段声明
前言
前面的文章介绍了正则表达式的基本语法,既然学会了语法,就要应用起来,因此这里搜集整理了50道题目,建议大家一定要尝试练习,说不定哪天面试笔试题会遇到。
正文
下面我们就来看看这50道题目,练习完肯定会有不少收获。文章来源微信公众号:转行学数据分析,50道题目答案请参见公众号历史文章。
1. \\d,\\W,\\s,\\B,.,*,+,?分别是什么?
2. (?=a),(?<!a),(?<=a),(?!a)分别是什么?
3. 什么是贪婪匹配和懒惰匹配?
4. \\d{1,2}*这样的写法对吗?请说明理由。
5. 怎么让正则表达式从字符串的右边开始匹配?
6. 写出验证用户名的正则表达式,用户名只能输入英文、数字和下划线。
7. 写出验证用户名的正则表达式,用户名只能输入汉字、英文、数字和下划线。
8. 验证用户密码,长度在6~18 之间,只能包含英文和数字。
9. 验证用户密码强度,最少6位,至少包括1个大写字母、1个小写字母、1个数字和1个特殊字符。
10. 匹配QQ号。
11. 匹配Email地址。
12. 匹配手机号。
13. 匹配固定电话号码。
14. 用正则表达式分别提取固定电话号码中的区号和电话号。
15. 匹配身份证号码。
16. 匹配出身份证号码中的区域代码。
17. 用正则表达式匹配出身份证号中的出生日期。
18. 匹配银行卡号。
19. 匹配邮政编码。
20. 匹配包含送货地址的字符串。
21. 匹配车牌号。
22. 匹配整数。
23. 匹配非零的负整数。
24. 匹配非零的正整数。
25. 匹配浮点数。
26. 匹配非负浮点数。
27. 匹配以下HTML中的文本信息:
Demand feedback