Jump to content

Regular Expression


NLWSH
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by JLogan3o13
Link to comment
Share on other sites

  • Moderators

@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 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!

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Link to comment
Share on other sites

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 by AutoBert
Link to comment
Share on other sites

Maybe this one  ?

$sContent1 = FileRead("file.txt")

$sNewContent1 = StringRegExpReplace($sContent1, "\R\h+\N+", "")
$sNewContent2 = StringRegExpReplace($sContent1, "(?m)^(\s+)|^\H+", "")
ConsoleWrite($sNewContent2)

 

 

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...