remove html tags from text

Questions, tips and tricks and techniques for scripting in Servoy

remove html tags from text

Postby Hans Nieuwenhuis » Sat Feb 25, 2012 5:44 pm

Hi,

I need to remove html tags from a text string.

In other solutions, I use the getAsPlainText method in combination with a hidden text field (html area) on a form.

But this solution runs as a batch server, so I guess I can not use this "trick" there ?

Regards,
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: remove html tags from text

Postby Joas » Mon Feb 27, 2012 10:34 am

You can use a regular expression:
Code: Select all
var _plainText = _htmlText.replace(/<\/{0,1}\w+>/g, "");
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: remove html tags from text

Postby Hans Nieuwenhuis » Mon Feb 27, 2012 11:55 am

Thanks,

But in my sample it still leaves the &nbsp; in the text.

Maybe there are more issues like that one ??

Googled some extra info and now I use this :

Code: Select all
data.replace(/<\/{0,1}\w+>/g,'').replace(/&[^;]+?;/g,''
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: remove html tags from text

Postby jcarlos » Mon Feb 27, 2012 8:33 pm

Why don't you try the SmartDoc plugin? (https://www.servoyforge.net/projects/smartdoc)

The part of the SmartDoc that does the extraction is Tika. But the SmartDoc does more than extracting text. It might be too much just for this. But if were you I'd check it out. I am sure that you'll find it very useful - it also can serve you well in many other solutions.

JC
Juan-Carlos Sanchez, Stanford University - Law and Economics
jcarlos
 
Posts: 578
Joined: Thu May 04, 2006 8:55 pm
Location: Palo Alto, California USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests