php正则表达式获取标题
我正在尝试从文本字符串中间删除内容标题。我可以使用正则表达式从该字符串中删除除这些字符串中的 标题(斜体) 之外的所有内容吗?或者有更好的方法吗?
Joe 用户写了一篇名为的博文 该类别中的 10 个最佳正则表达式 正则表达式。
Jane 用户写了一篇名为的博文 正则表达式很难! 在技术问题类别中。
我试图想出一个正则表达式来解决这个问题,但我认为可能需要两个。诀窍在于粗体文本始终相同,因此您可以搜索它,如下所示:
的博客文章)
正则表达式:删除之前的所有内容(包括写了一篇名为正则表达式 :删除类别及其后的所有内容。
I'm trying to strip content titles out of the middle of text strings. Could I use regex to strip everything out of this string except for the title (in italics) in these strings? Or is there a better way?
Joe User wrote a blog post called
The 10 Best Regex Expressions in the category Regex.Jane User wrote a blog post called
Regex is Hard! in the category TechProblems.
I've tried to come up with a regex expression to cover this, but I think it might need two. The trick is that the text in bold is always the same, so you could search for that, like this:
regex: delete everything before and including wrote a blog post called
regex: delete in the category and everything after it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以:
^ 是行的开头
.+ 是一些字符(一对多)
(.+) 相同,但内容将在 \1 中可用,用于 preg_replace()
$ 是行尾
So:
^ is start of line
.+ is some characters (one to many)
(.+) same, but the content will be available in \1, for preg_replace()
$ is the end of line