dkim18
asked on
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("(?!)[<blin k>[</blink >]]", "");
can someone help with this?
Thanks,
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("(?!)[<blin
can someone help with this?
Thanks,
ASKER
No, it didn't work. when I checked the page source, it didn't remove blink tags at all.
What does your source string look like exactly?
str.replaceAll("(<blank>|< /blank>)", "")
Oops i considered it as <blank> instead of <blink> change accordingly..
Did you also want to remove everything wrapped by the blink tag?
ASKER
<!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>
<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>
mine will work
String name="<H1><BLINK> BLINK </BLINK></H1><BR>";
String raj=name.replaceAll("(<BLI NK>|</BLIN K>)","");
System.out.println(raj);
output will be
<H1> BLINK </H1><BR>
Is this what you are expecting?
String raj=name.replaceAll("(<BLI
System.out.println(raj);
output will be
<H1> BLINK </H1><BR>
Is this what you are expecting?
ASKER
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.
that is strange...
str.replaceAll("(<blink>|<
I also think I need to prepend the first argument with "(?!)" for a case-insensitive replacement.
try:
str.replaceAll("<[bB][lL][ iI][nN][kK ]>.*?</[bB ][lL][iI][ nN][kK]>", "");
str.replaceAll("<[bB][lL][
str.replaceAll("(<[bB][lL] [iI][nN][k K]>|</[bB] [lL][iI][n N][kK]>)", "");
this wont strip the content between the tags ...hoping that is what you are looking for
this wont strip the content between the tags ...hoping that is what you are looking for
ASKER
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("(<BLI NK>|</BLIN K>)","");
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)reques t;
HttpServletResponse res = (HttpServletResponse)respo nse;
CharArrayWrapper responseWrapper =
new CharArrayWrapper(res);
chain.doFilter(req,respons eWrapper);
String str = responseWrapper.toString() ;
// str.replaceAll("(<blink>|< /blink>)", "");
System.out.println(str);
it doesn't work. If I tested this,
String name="<H1><BLINK> BLINK </BLINK></H1><BR>";
String raj=name.replaceAll("(<BLI
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)reques
HttpServletResponse res = (HttpServletResponse)respo
CharArrayWrapper responseWrapper =
new CharArrayWrapper(res);
chain.doFilter(req,respons
String str = responseWrapper.toString()
// str.replaceAll("(<blink>|<
System.out.println(str);
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);
BTW, if you want to ignore case then you can do it using this way:
Pattern p = Pattern.compile("<blink>|<
Matcher m = p.matcher(responseWrapper.
String str = m.replaceAll("');
System.out.println(str);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
str.replaceAll("<blink>.*?