Stripping HTML tags

Hi,

I was wondering if there was an efficient way to strip out HTML tags from strings.  I wrote the following function, but would appreciate any suggestions for improvement.

{first {if[y~“<”;x[1]:1b]; x[0],:$[not x[1];y;()]; if[y~“>”;x[1]:0b]; x}/[(enlist (“”;0b)),x]} “1 <b> 3 <\b> 5”

Thanks,

Victor

On Apr 12, 2012, at 4:16 PM, Victor Wong wrote:

> I was wondering if there was an efficient way to strip out HTML tags
from strings. I wrote the following function, but would appreciate any
suggestions for improvement.
>
> {first {if[y~“<”;x[1]:1b]; x[0],:$[not x[1];y;()]; if[y~“>”;x[1]:0b];
x}/[(enlist (“”;0b)),x]} “1 **3 <\b> 5”

yes, don’t use q

q){system"echo ‘“,x,”’|sed -r ‘s/<[^>]*>//g’"}“1 3 <\b> 5”
“1 3 5”**

On Apr 12, 2012, at 7:14 PM, Aaron Davies wrote:

> On Apr 12, 2012, at 4:16 PM, Victor Wong wrote:
>
>> I was wondering if there was an efficient way to strip out HTML tags
from strings. I wrote the following function, but would appreciate any
suggestions for improvement.
>>
>> {first {if[y~“<”;x[1]:1b]; x[0],:$[not x[1];y;()]; if[y~“>”;x[1]:0b];
x}/[(enlist (“”;0b)),x]} “1 **3 <\b> 5”
>
> yes, don’t use q
>
> q){system"echo ‘“,x,”’|sed -r ‘s/<[^>]*>//g’"}“1 3 <\b> 5”
> “1 3 5”

though if you really have to, there’s a nice pattern for “mask out
portions of this list during which some property was true”

q){x where not m|(<>)m:max x=/:“<>”}“1 3 <\b> 5”
“1 3 5”

Aaron Davies
aaron.davies@gmail.com**

Thanks.  That is a very neat solution.