正则表达式将开始标记和结束标记匹配为新行
我一直在制作一个信件编译系统(以在填写问卷后节省人们的时间),并且在项目接近尾声时我们发现了一个错误。长话短说,如果没有这个正则表达式,修复将需要很多小时 - 这就是为什么我请求您的帮助!
我们有一些文本包含以下内容...
"<k>This is the start of the paragraph
This is some more of the paragraph.
And some more";
我基本上需要一个正则表达式来搜索开始标记“
”,以及它遇到的第一个新行“\ r\n”?然后将内容插入到我可以使用的变量中(删除了
但新行代码“\r\n”保留在原处)。
我使用的是 PHP,文本(如上面的示例)存储在 MySQL 中。
请帮忙!
我保证在修复这个错误后我会好好学习这些! :)
I've been producing a letter compilation system (to save people time after a questionaire has been filled in) and near the end of the project we've found a bug. Long story short it would take many hours to fix without this regular expression - which is why I'm asking for your fine help!
We have some text that contains the following...
"<k>This is the start of the paragraph
This is some more of the paragraph.
And some more";
I basically need a regular expression that can search for the opening tag, "<k>
", and also the first new line it comes across "\r\n"? and then insert the contents into a variable I can then use (with the <k>
removed but the new line codes, "\r\n", left in place).
I'm using PHP and the text (like the example above) is stored in MySQL.
Please help!
I promise I'll learn these properly after I've fixed this bug! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 5.3,您可以使用这样的闭包:
输出是:
我假设文本中可能有多个
标记,因此,我将所有文本跟随标签进入一个名为 matches 的数组。作为进一步的示例...具有以下输入:
输出为:
If you are using 5.3 you can make some use of closures like this:
Output is:
I'm assuming there could be multiple
<k>
tags in the text, and therefore, I put all the text that follows the tag into an array called matches.As a further example... with the following input:
The output is:
可能会起作用。
would probably work.