[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Removing blink tag - regular expression and using replaceAll()

Posted on 2005-04-17
15
Medium Priority
?
267 Views
Last Modified: 2010-03-31
Hello!

I am trying to removes all BLINK tags from the resource to which it is applied. So, I am using replaceAll() like this, but didn’t work.

str.replaceAll("(?!)[<blink>[</blink>]]", "");

can someone help with this?

Thanks,

0
Comment
Question by:dkim18
  • 5
  • 5
  • 4
  • +1
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13802781
try something like:

str.replaceAll("<blink>.*?</blink>", "");
0
 

Author Comment

by:dkim18
ID: 13802801
No, it didn't work. when I checked the page source, it didn't remove blink tags at all.
0
 
LVL 92

Expert Comment

by:objects
ID: 13802818
What does your source string look like exactly?
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 8

Expert Comment

by:koppcha
ID: 13803020
str.replaceAll("(<blank>|</blank>)","")
0
 
LVL 8

Expert Comment

by:koppcha
ID: 13803068
Oops i considered it as <blank> instead of <blink> change accordingly..
0
 
LVL 92

Expert Comment

by:objects
ID: 13803079
Did you also want to remove everything wrapped by the blink tag?
0
 

Author Comment

by:dkim18
ID: 13803100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
This is the source and I want to remove all blink tags.

<HEAD>
<TITLE> blink page-HW#10</TITLE>

</HEAD>

<BODY>
<CENTER>
<H1><BLINK> BLINK </BLINK></H1><BR>
<H1><blink> BLINK </blink></H1><BR>

<H1><BlInK> BLINK </BlInK></H1>

</CENTER>
</BODY>
</HTML>
0
 
LVL 8

Expert Comment

by:koppcha
ID: 13803103
mine will work
0
 
LVL 8

Expert Comment

by:koppcha
ID: 13803110
String name="<H1><BLINK> BLINK </BLINK></H1><BR>";
String raj=name.replaceAll("(<BLINK>|</BLINK>)","");
System.out.println(raj);

output will be
<H1> BLINK </H1><BR>

Is this what you are expecting?
0
 

Author Comment

by:dkim18
ID: 13803120
This didn't work at all...
that is strange...

str.replaceAll("(<blink>|</blink>)", "");

I also think I need to prepend the first argument with "(?!)" for a case-insensitive replacement.
0
 
LVL 92

Expert Comment

by:objects
ID: 13803145
try:

str.replaceAll("<[bB][lL][iI][nN][kK]>.*?</[bB][lL][iI][nN][kK]>", "");
0
 
LVL 8

Expert Comment

by:koppcha
ID: 13803188
str.replaceAll("(<[bB][lL][iI][nN][kK]>|</[bB][lL][iI][nN][kK]>)","");

this wont strip the content between the tags ...hoping that is what you are looking for
0
 

Author Comment

by:dkim18
ID: 13803248
This is strange. The out of the following  is exactly above source and if I put      str.replaceAll("(<blink>|</blink>)", "");
it doesn't work. If I tested this,

 String name="<H1><BLINK> BLINK </BLINK></H1><BR>";
String raj=name.replaceAll("(<BLINK>|</BLINK>)","");
System.out.println(raj);

Yes, it worked! So, why this isn't working...??
+++++++++++++++++++++++++++++++++

public void doFilter(ServletRequest request,
                       ServletResponse response,
                       FilterChain chain)
      throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest)request;
    HttpServletResponse res = (HttpServletResponse)response;
   
      CharArrayWrapper responseWrapper =
        new CharArrayWrapper(res);
      chain.doFilter(req,responseWrapper);
     
     String str = responseWrapper.toString();
   // str.replaceAll("(<blink>|</blink>)", "");                  
     System.out.println(str);
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13803272
The line is commented...

BTW, if you want to ignore case then you can do it using this way:
Pattern p = Pattern.compile("<blink>|</blink>", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(responseWrapper.toString());
String str = m.replaceAll("');
System.out.println(str);
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 13803275
if you want keep whats inside the blink tag then the following is simpler:

str.replaceAll("</?[bB][lL][iI][nN][kK]>", "");


> So, why this isn't working...??

You need to do:

str = str.replaceAll("</?[bB][lL][iI][nN][kK]>", "");

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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