String regex = "<\\s*?(/)??[b-hj-z].*?>";

On Thu, Jul 23, 2009 at 11:04 AM, vunet <vunet...@gmail.com> wrote:

>
> Hi experts,
>
> I need to strip HTML out of the code BUT with some filter, i.e. keep
> certain tags in. I got as far as this below where it really strips
> HTML and keeps the tags I want (<a> and <i>) but it does not keep
> ending tags (</a> and </i>). Please see clear example below:
>
> String in = "<i>Italic here</i> and <a href='http://www.x.com'>link
> here</a> and the <span>rest of removed HTML </span>";
> regex = "<[^((\\s*I)|(\\s*A))].*?>";
> System.out.println(regex);
> System.out.println( java.util.regex.Pattern.compile(regex,
> java.util.regex.Pattern.CASE_INSENSITIVE).matcher(in).replaceAll
> ("") );
>
> Result: <i>Italic here and <a href='http://www.x.com'>link here and
> the rest of removed HTML
> Desired result: <i>Italic here</i> and <a href='http://www.x.com'>link
> here</a> and the rest of removed HTML
>
> Please recommend the solution if possible.
> Thank you.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to