NLWSH Posted September 7, 2016 Posted September 7, 2016 Hello, i´ve got a problem with an exercise including regular expressions. I have to definitely solve it with regular expressions. The finished script should move strings between white spaces and tabs out of a .txt document and paste it into a new document. I have found the expression that should do it but I really don´t know how to handle it. It´s in line 8 of regtest.au3. Neues Textdokument.txt
NLWSH Posted September 7, 2016 Author Posted September 7, 2016 37 minutes ago, NLWSH said: $start = 1 $datei = FileOpen("\T-End-geliefert - Kopie.dmt") $zeile = FileReadLine($datei, $start) while 1 If $datei == 1 Then FileWriteLine("\abc","$zeile", $start) ElseIf $datei Not == 1 Then @CRLF EndIf $new = StringRegExp($datei, "([^\S])") MsgBox(0, "", $new) wend
Daeth Posted September 7, 2016 Posted September 7, 2016 That's not the correct RegExp. If you want to capture strings between a whitespace or tab, the expression would be: [\x20\x09](.*)[\x20\x09]
NLWSH Posted September 7, 2016 Author Posted September 7, 2016 (edited) Hallo Zusammen, ich habe ein Problem bei der Benutzung von regulären Ausdrücken. Ich muss aus einem Textdokument in dem sich Leerzeichen und unvollständige Daten befinden alle Leerzeichen entfernen, die unvollständigen Daten löschen (rt) und dann die brauchbaren Daten in ein neues Textdokument einfügen. Wichtig ist nur, dass reguläre Ausdrücke auf jeden Fall benutzt werden müssen. Ich habe zwar den Befehl gefunden, der die Leerzeichen eigentlich entfernen sollte aber das bekomme ich nicht ans Laufen. Im Anhang findet ihr das zu bearbeitende Textdokument. Quote Translated: Hello everybody, I have a problem with the use of regular expressions . I have to remove all spaces from a text document in which space and incomplete data are , delete the incomplete data ( rt ) and then insert the useful data in a new text document . What matters is that regular expressions to be used in any case . Although I have found the command that was supposed to remove the spaces but I do not get up and running . In the appendix you will find the text document to edit. $start = 1 $datei = FileOpen("\Neues Textdokument 2.0") $zeile = FileReadLine($datei, $start) while 1 $new = StringRegExp($zeile, "([\x20\x09](.*)[\x20\x09])") MsgBox(0, "", $new) If $zeile == 1 Then FileWriteLine("\abc","$zeile", $start) ElseIf $zeile Not == 1 Then FileReadLine($zeile + 1, $start) EndIf WEnd Neues Textdokument 2.0.txt Edited September 7, 2016 by JLogan3o13
Moderators JLogan3o13 Posted September 7, 2016 Moderators Posted September 7, 2016 (edited) @NLWSH I have moved your topic to the appropriate forum, please be mindful of where you post in the future. Also, as this is an English-speaking forum, you will find more help if you post in English (using Google Translate if necessary). I have translated your first post to the best of Google's ability. If it easier for you, you can try the German forum: https://autoit.de/ Edit: Topics merged as well. Please stick to one thread. Edited September 7, 2016 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
jchd Posted September 7, 2016 Posted September 7, 2016 You need to use StringRegExpReplace if you need to change the text. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
AutoBert Posted September 7, 2016 Posted September 7, 2016 (edited) I think TE has got a solution with StringRegExp: #include <Array.au3> $sText = FileRead(@ScriptDir & '\Neues Textdokument 2.0.txt') $aNew = StringRegExp($sText, '(?s)(\d+=geliefert)', 3) _ArrayDisplay($aNew) in https://autoit.de/index.php/Thread/84572-Reguläre-Ausdrücke/?postID=676580#post676580. I am not able to define a RegEx-Pattern (Holy Zuse) has forgotten to implement this func while updating my brain.exe from Ver1985 to Ver2016) but one post before i posted a solution where no RegEx is needed. Edited September 7, 2016 by AutoBert
mikell Posted September 7, 2016 Posted September 7, 2016 Does this give the expected result ? $s = FileRead("Neues Textdokument.txt") $r = StringRegExpReplace($s, '(?m)\h+\R?|^\R', "") Msgbox(0,"", $r)
AutoBert Posted September 7, 2016 Posted September 7, 2016 No, the lines with rt only shouldn't be in result
jguinch Posted September 7, 2016 Posted September 7, 2016 Maybe this one ? $sContent1 = FileRead("file.txt") $sNewContent1 = StringRegExpReplace($sContent1, "\R\h+\N+", "") $sNewContent2 = StringRegExpReplace($sContent1, "(?m)^(\s+)|^\H+", "") ConsoleWrite($sNewContent2) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
mikell Posted September 8, 2016 Posted September 8, 2016 16 hours ago, AutoBert said: No, the lines with rt only shouldn't be in result OK, I misunderstood ... $s = FileRead("Neues Textdokument.txt") $r = StringRegExpReplace($s, '(?m)^\h*(rt)?\h*\R?', "") Msgbox(0,"", $r)
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