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
487 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPSessionBindingListernter not configured in deployment descriptor 2 70
Advice in Xamarin 21 109
Java string replace 11 61
Android development question 2 78
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 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