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
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
485 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 75

Expert Comment

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

Open in new window

0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

792 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