0

I want to take one part of description from html tag. But I do not know how can I apply it?

Here is my Html tag:

İstanbul Çağlayan Adliyesi’nde teröristler tarafından silahla vurularak öldürülen savcı Mehmet Selim Kiraz’ın babası hastanede taziyeleri kabul ederken, yakınları da gözyaşı döktü. Savcı Kiraz’ın cenazesi Adli Tıp Kurumu morguna götürüldü.

I need to parse this part from description.

The following code give me all sentences in the description but I don't want some sentences which are in <a href=...></a> tags:

viewHolder.txtViewDescription.setText(Html.fromHtml(itemsData.get(position).getDescription()));

How can I apply it? Thanks for help...

serdanarik
  • 45
  • 1
  • 9

3 Answers3

1

If I understand you well, you are trying to get the whole text, but without this from tags, so you could use a regex like this

str = str.replaceAll("<a href=([^<]*)>([^<]*)</a>", "");

and remove all tags. Then you could use the line you wrote to extract the text

viewHolder.txtViewDescription.setText(Html.fromHtml(itemsData.get(position).getDescription()));

Hopefully this helps you

Gabriella Angelova
  • 2,985
  • 1
  • 17
  • 30
1

You can use this Regular expression to remove all anchor tags.

String your_string = "<a>your html content</a>useful text"
String exp = "<a href=.*</a>";
String result = your_string.replaceAll(exp, "");
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33
0

Try this regular expression for replacing all the hyperlink tags.

String regx = "<a [\\s]*href .*></a>";
String result = description.replaceAll(regx);
Bojan Kseneman
  • 15,488
  • 2
  • 54
  • 59
Kartheek
  • 7,104
  • 3
  • 30
  • 44