开发者

How to Remove a not - html tag - CID

开发者 https://www.devze.com 2023-02-18 02:04 出处:网络
Given text like: This is my reply. This is paragraph one. This is paragraph two. Capture everything before me as this is the last sentence.

Given text like:

This is my reply. This is paragraph one.

This is paragraph two. Capture everything before me as this is the last sentence.

[cid:0BE7856F-9507-4AEA-854D-C01A6CFAF15F]
[cid:1DA3C231-846D-4490-9458-04A2484F4294]
[cid:33225087-994A-4FAF-B74D-5D56F334F29D]
开发者_StackOverflow社区

What's the best way to remove the cid tags, resulting in just:

This is my reply. This is paragraph one.

This is paragraph two. Capture everything before me as this is the last sentence.


If you want to catch that very specific format you'd do:

  regex = /\[cid:[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\]/
  body[0..(body =~ regex).to_i-1]

If you want to loosen it up a little you'd do:

  body[0..(body =~ /\[cid:/).to_i-1]

If you aren't sure there will be content before the [cid declaration then you should pull it out and do this:

  regex = # choose your expression
  test = body =~ regex
  body[0..(test.nil? ? -1 : test - 1)]
0

精彩评论

暂无评论...
验证码 换一张
取 消