-2

I have this HTML string input which is output from Html.toHtml(EditText.getSpanned())

<font color="#000000"><font face="DEFAULT">foo</font></font>
<font color ="#4149b6"><font face="AlexBrush-Regular">baa</font></font>

I'd like to use regex to remove some HTML tags (simplify it) so that the output is:

<font color="#000000" face="DEFAULT">a</font>
<font color ="#4149b6" face="AlexBrush-Regular">b</font>

Can anyone suggest how to do this with regex or any string replacement function ?

This is the string pre-processing before using Jsoup to parse the html.

I just want the value of the attr (color/face) of font tag

Korr Iamnot
  • 309
  • 5
  • 15
  • 3
    Please, before doing regex on html, [read this](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags?rq=1) – randers Jan 17 '16 at 09:43
  • 2
    I think you're trying to find help with the "solution" you've found yourself rather than the actual problem, if you supply us with information about the real problem (e.g. "I need to turn this into that and I wanted to use this...etc") we might be able to help you in multiple different / better ways :) – SidOfc Jan 17 '16 at 09:48
  • 1
    I think you want an HTML parser. Not regular expressions. – Dawood ibn Kareem Jan 17 '16 at 09:49
  • Ok that is the output from Html.toHtml(EditText.getSpanned()), so I may look weird for general but I want the output to be parsed by Jsoup lib. – Korr Iamnot Jan 17 '16 at 09:57

1 Answers1

0
String theHtml = theHtml.replace("><font","").replace("</font></font color","</font><font color");

That's it, easy.

Korr Iamnot
  • 309
  • 5
  • 15