Sign in to follow this  
Followers 0
leuce

Removing HTML-style tags from text using a script

9 posts in this topic

G'day everyone

I have pieces of text with HTML-style tags in them, like this:

<a0>This is a <a0/><b1>house<b1/>.

and I'd like to use a script to remove the tags, so that I end up wit this:

This is a house.

Of course, I could copy the text, past it into a text editor, and use regex find/replace to remove the tags, then copy the text again, but that is a long way and it is dependent on the user's computer having the correct text editor installed. I was hoping that there is some way in AutoIt itself to do this.

Thanks

Samuel

Share this post


Link to post
Share on other sites



Use File Read or _InetGetSource() and try this:

$sString = "<a0>This is a <a0/><b1>house<b1/>."
$sString = StringRegExpReplace($sString, '(?s)(?i)\<[^\>]*\>', '')
MsgBox(0,'', $sString)
The original $sString will be the FileRead() or _InetGetSource().


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#include <File.au3>

Dim $lines, $file = "test.txt"

If Not _FileReadToArray($file, $lines) Then
    MsgBox(16, "Error 1", "File could not be read to array.")
    Exit
Else
    If IsArray($lines) And $lines[0] > 0 Then
        For $i = 1 To $lines[0]
            $lines[$i] = StringRegExpReplace($lines[$i], '(?s)(?i)\<[^\>]*\>', '')
        Next
        FileDelete($file)
        _FileWriteFromArray($file, $lines, 1)
    EndIf
EndIf

Something like that.

Share this post


Link to post
Share on other sites
#include <File.au3>

Dim $lines, $file = "test.txt"

If Not _FileReadToArray($file, $lines) Then
    MsgBox(16, "Error 1", "File could not be read to array.")
    Exit
Else
    If IsArray($lines) And $lines[0] > 0 Then
        For $i = 1 To $lines[0]
            $lines[$i] = StringRegExpReplace($lines[$i], '(?s)(?i)\<[^\>]*\>', '')
        Next
        FileDelete($file)
        _FileWriteFromArray($file, $lines, 1)
    EndIf
EndIfoÝ÷ Ù*&zØb bëajßêº^6ájÝý²z-­"y¢Óhç~ÅWy§S 
ëk$­®)àEèÆ^¦V{¥Ú"µ©eÂ+-²¶§X¤y«­¢+ØÀÌØíÍMÑÉ¥¹=ÕÑAÕÐôMÑÉ¥¹IáÁIÁ±¡¥±I ÌäíÑÍйÑáÐÌä줰Ìäì ý̤ ý¤¤ÀäÈì±ÐímxÀäÈìÐít¨ÀäÈìÐìÌäì°ÌäìÌäì¤
All you need is 1 line really... and a FileWrite if you are going to write it to a file.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I guess you're right. Could just read the entire file into a variable regardless of line breaks. Not really sure what I was thinking.

Share this post


Link to post
Share on other sites

I guess you're right. Could just read the entire file into a variable regardless of line breaks. Not really sure what I was thinking.

If it's any consolation, when I was writing it, I was trying to do it the hard way myself with just StringRegExp() and took me 20 minutes to realize that I was just making it hard on myself.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks, everyone. All your solutions give me the answer "1", but at least now I know what I should tinker with.

Share this post


Link to post
Share on other sites

Thanks, everyone. All your solutions give me the answer "1", but at least now I know what I should tinker with.

You need Beta 3.2.1.8 at least for it to work, and the answer with be right.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0