• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Removing blink tag - regular expression and using replaceAll()

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
dkim18
Asked:
dkim18
  • 5
  • 5
  • 4
  • +1
1 Solution
 
objectsCommented:
try something like:

str.replaceAll("<blink>.*?</blink>", "");
0
 
dkim18Author Commented:
No, it didn't work. when I checked the page source, it didn't remove blink tags at all.
0
 
objectsCommented:
What does your source string look like exactly?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
koppchaCommented:
str.replaceAll("(<blank>|</blank>)","")
0
 
koppchaCommented:
Oops i considered it as <blank> instead of <blink> change accordingly..
0
 
objectsCommented:
Did you also want to remove everything wrapped by the blink tag?
0
 
dkim18Author Commented:
<!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
 
koppchaCommented:
mine will work
0
 
koppchaCommented:
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
 
dkim18Author Commented:
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
 
objectsCommented:
try:

str.replaceAll("<[bB][lL][iI][nN][kK]>.*?</[bB][lL][iI][nN][kK]>", "");
0
 
koppchaCommented:
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
 
dkim18Author Commented:
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
 
aozarovCommented:
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
 
objectsCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 5
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now