Sign in to follow this  
Followers 0
Carlo84

Replace text using wildcards.

2 posts in this topic

Hi all,

I have this function and i'm wanting to replace the top and end using a wildcard, because its contents will never be the same.

I have searched the forum and googled it, but cant find any information (nothing i could understand at least) on how to use wildcards using a string.

I seem only to be able to replace exact strings?

this is the Function so far. ( with '*' on 2nd last line representing the wildcard.

Could someone please point me in the right direction?

Thanks

Func strip()
    InetGet ( "http://domain.com/someFile.php","321cba.txt", 1)

    $file = FileOpen("321cba.txt", 0)

; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

; Read in 1 character at a time until the EOF is reached
    While 1
        $chars = FileRead($file)
        If @error = -1 Then ExitLoop
        $rawHTML=$chars
    Wend
        FileClose($file)
;MsgBox(0,"",$rawHTML)
        MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($rawHTML, "<!doctype * <body>", ""))
EndFunc

Share this post


Link to post
Share on other sites



Hi all,

I have this function and i'm wanting to replace the top and end using a wildcard, because its contents will never be the same.

I have searched the forum and googled it, but cant find any information (nothing i could understand at least) on how to use wildcards using a string.

I seem only to be able to replace exact strings?

this is the Function so far. ( with '*' on 2nd last line representing the wildcard.

Could someone please point me in the right direction?

Thanks

Func strip()
    InetGet ( "http://domain.com/someFile.php","321cba.txt", 1)

    $file = FileOpen("321cba.txt", 0)

; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

; Read in 1 character at a time until the EOF is reached
    While 1
        $chars = FileRead($file)
        If @error = -1 Then ExitLoop
        $rawHTML=$chars
    Wend
        FileClose($file)
;MsgBox(0,"",$rawHTML)
        MsgBox(0, "Regular Expression Replace Test", StringRegExpReplace($rawHTML, "<!doctype * <body>", ""))
EndFunc

This StringRegExpReplace() replaces all text up to and including <body> with "Text Replaced with this line." & @CRLF & "\2".

"\2" being a back reference containing the text "<body>".

strip()

Func strip()
    InetGet("http://domain.com/someFile.php", "321cba.txt", 1)
    $chars = FileRead("321cba.txt")
    ;ConsoleWrite($chars & @CRLF)
    MsgBox(0, "Regular Expression Replace Test", _
        StringRegExpReplace($chars, "(?s)(?i)(<!doctype.*)(<body>)", _
        "Text Replaced with this line." & @CRLF & "\2"))
EndFunc ;==>strip

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