NLWSH

Regular Expression

12 posts in this topic

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

Share this post


Link to post
Share on other sites



Can you post the code please?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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]

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by JLogan3o13

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by JLogan3o13

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by AutoBert

Share this post


Link to post
Share on other sites

Does this give the expected result ?

$s = FileRead("Neues Textdokument.txt")
$r = StringRegExpReplace($s, '(?m)\h+\R?|^\R', "")
Msgbox(0,"", $r)

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

No, the lines with rt only shouldn't be in result

102_StringRegExpReplace.jpg

Share this post


Link to post
Share on other sites

#12 ·  Posted

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)

 

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