Carlo84 Posted December 6, 2009 Share Posted December 6, 2009 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?ThanksFunc 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 _SplashProgressImage | _Regionselector | _IsPressed360 | _UserAccountContol_SetLevel | _ListSubFolders Link to comment Share on other sites More sharing options...
Malkey Posted December 6, 2009 Share Posted December 6, 2009 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?ThanksFunc 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>", "")) EndFuncThis 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now