• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

How can i remove the some of the mime content from the following data stored in a String

From the below data, how can i remove the mime content types like image,video and retain the text/plain and text/html content types using java regular expression?

Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

This is line 1.
This is line 2.

--boundary-
Content-Type: text/html;
      charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: enc type

<HTML>
   <BODY>
           This is html body section.
   </BODY>
</HTML>

--boundary-
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit

This is line 3.
This is line 4

--boundary-
Content-Type: image/jpeg; name=image001.jpg
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQAAAQABAAD
GBgXFBYWGh0lHxobIxwWFiAsICMmJykqKRkfLTAtKDAlKCko/9sAQwEHBwcKCAoTCgoTKBoWGigo
KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgo/8AAEQgBLADR

--boundary-
0
soundar_vk
Asked:
soundar_vk
  • 2
  • 2
  • 2
1 Solution
 
ramelongCommented:
You can use a regular expression like this:

/--boundary-\nContent-Type: image/jpeg; name=[a-zA-Z0-9_]\.[a-zA-Z]+\nContent-Transfer-Encoding: base64\n+[0-9A-Z\/\n]+--boundary-\n*/
0
 
soundar_vkAuthor Commented:
Thanks for the reply. But it was not helpful. Basically i need the regular expression starts with Content-Type: Some-Type and ends with something like --boundary-1138-29572-abc-123.

0
 
käµfm³d 👽Commented:
Try this:
(?m)^(?:Content-|-+boundary)

Open in new window

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
käµfm³d 👽Commented:
Correction:
(?m)^(?:Content-|-+boundary).*$

Open in new window

0
 
ramelongCommented:
Could you be more specific? You need to determinate with some degree of precision what are in between the limits you remarked, because with this specification you may extract valued data instead.
0
 
soundar_vkAuthor Commented:
This worked( If i want to remove image type).
^((?m)Content-Type:\\s{0,}image/jpeg.*?-+boundary.*?)$

Thanks all for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now