Solved

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

Posted on 2011-03-17
6
477 Views
Last Modified: 2013-11-24
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
Comment
Question by:soundar_vk
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Expert Comment

by:ramelong
ID: 35162633
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
 

Author Comment

by:soundar_vk
ID: 35162737
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
 
LVL 74

Expert Comment

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

Open in new window

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 35164193
Correction:
(?m)^(?:Content-|-+boundary).*$

Open in new window

0
 
LVL 6

Expert Comment

by:ramelong
ID: 35164841
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
 

Author Closing Comment

by:soundar_vk
ID: 35165075
This worked( If i want to remove image type).
^((?m)Content-Type:\\s{0,}image/jpeg.*?-+boundary.*?)$

Thanks all for the help.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This article will show, step by step, how to integrate R code into a R Sweave document
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now