ruby-on-rails - 寻找有关如何匹配模式的想法,可能与否?

标签 ruby-on-rails ruby regex

我正在寻求帮助来创建模式匹配以接收电子邮件。最终目标是接收传入消息并仅提取回复消息,而不是所有尾随垃圾(以前的线程、签名、数据戳 header 等...)

下面是两种相同的格式:

格式一:

The Message is here, etc etc can span a random # of lines

On Nov 17, 2010, at 4:18 PM, Person Name wrote:

lots of junk down here which we don't want

格式二:

The Message is here, etc etc can span a random # of lines

On Nov 17, 2010, at 4:18 PM, Site <yadaaaa+adad@sitename.com> wrote:

lots of junk down here which we don't want

格式 3:

The Message is here, etc etc can span a random # of lines

On Fri, Nov 19, 2010 at 1:57 AM, <customerserviceonline@pge.com> wrote:

lots of junk down here which we don't want

对于上面的两个例子,我想创建一个模式匹配来找到第 2 行的第一个实例。然后仅返回该行上方的内容。我不想要那个分隔线。

我无法匹配日期戳,但我可以匹配逗号后的所有内容,因为这是我的控制。

所以这个想法,寻找这两个静态项目中的任何一个:

, Site <yadaaaa+adad@sitename.com> wrote:
, Person Name wrote:

然后把所有高于该位置的东西拿走。你怎么认为。这可能吗?

最佳答案

我会添加一种不同的方法:为什么您不阅读所有内容并在匹配停止的行时中断?

关于ruby-on-rails - 寻找有关如何匹配模式的想法,可能与否?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4217838/

相关文章:

ruby-on-rails - cancancan authorize_resource 未按预期工作

ruby-on-rails - Rails 邮件程序连接被拒绝 - localhost

javascript - rails : Javascript not getting to heroku

r - 使用 R 包 RefManageR 调整文本引用

javascript - 正则表达式不起作用

c++ - Boost C 正则表达式 - 如何返回所有匹配项

jquery - Rails 参数解析,需要转义吗?

ruby-on-rails - wicked_pdf_image_tag 给定未定义的图像路径名

java - ruby如何加载相对于jar中源代码的图像

ruby-on-rails - rails : How to change the title of a page?