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
490 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 75

Expert Comment

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

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

739 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