Sign in to follow this  
Followers 0
sam71

Modifying text file:StringRegExp ?

11 posts in this topic

Hello AUTOIT gurus,

I would appreciate your help to modify/creating text files.

I sucessfully recognize the expression i want and save the file but i think there is a far better way to do it:

func expresso()

Run ('C:\Program Files\Ultrapico\Expresso\expresso.Exe blank.xso')

WinWaitActive("Expresso - blank.xso","",5)

send('!F')

SEND('{ENTER}')

send('R')

send('R')

SEND('{ENTER}')

WinWaitActive("Read sample text from a file","",5)

ControlSend("Read sample text from a file", "", "[CLASS:Edit; INSTANCE:1]",'DIR_LST.TXT');Open DIR_LST

SEND('{ENTER}')

WinWaitActive("Expresso - blank.xso","",5)

ControlSend("Expresso - blank.xso", "", "[CLASS:WindowsForms10.EDIT.app.0.378734a; INSTANCE:1]",'\bXX\w*-\d\d\d-\w')

SEND('{f5}')

SLEEP(1000)

send('!T')

send('T')

send('X')

send('M')

WinWaitActive("Export the match results to a file","",5)

ControlSend("Export the match results to a file", "", "[CLASS:Edit; INSTANCE:1]",'DIR_LST.TXT');Save DIR_LST

SEND('{ENTER}')

SLEEP(500)

send('Y')

send('!F')

SEND('{ENTER}')

send('X')

SLEEP(500)

send('N')

EndFunc

The other think i would like to do is recognizing an expression and copying all the line of this expression in another file.

Every helpfull TIP is also welcome to modify text file with autoit.

Thanks much for your time.

Share this post


Link to post
Share on other sites



Before you get on to this specific problem it may help to clean up that code a bit so we can get a better idea of what you are doing. It appears ro me that You are attempting to access some menu items in Expresso. If that is the case then start by looking at WinMenuSelectItem() in the help file. Also please enclose your code in code tags. If you hover over the toolbar buttons of the editor you will find the button that says "Insert Code Snippet" and it looks similar to <>.

I'm sure that a RegExp is what will be best here but we need to get this cleaned up or at least heavily remarked and it will also help if you give us a sample of the text and what portion you want to extract.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Before you get on to this specific problem it may help to clean up that code a bit so we can get a better idea of what you are doing. It appears ro me that You are attempting to access some menu items in Expresso. If that is the case then start by looking at WinMenuSelectItem() in the help file. Also please enclose your code in code tags. If you hover over the toolbar buttons of the editor you will find the button that says "Insert Code Snippet" and it looks similar to <>.

I'm sure that a RegExp is what will be best here but we need to get this cleaned up or at least heavily remarked and it will also help if you give us a sample of the text and what portion you want to extract.

Hello geosoft,

Yes what i 'm trying to do is recognizing saving this specific expression: "\bXX\w*-\d\d\d-\w" in a text file ,and i'de like to do it without expresso if possible.

I would also like to coy all the line where the expression appear in nother file.

I understand stringregexp is to check if the pexression exist but i don;t know what to do from here.

Thanks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hello geosoft,

Yes what i 'm trying to do is recognizing saving this specific exp​ression: "\bXX\w*-\d\d\d-\w" in a text file ,and i'de like to do it without expresso if possible.

I would also like to coy all the line where the exp​ression appear in nother file.

I understand stringregexp is to check if the pexression exist but i don;t know what to do from here.

Thanks

StringRegExp() Can be used for much more than just checking for the existance of a string. We would have to see some actual text to verify your exp​ression but assuming that you have it correct then it should be

$sFile = "Existing.txt" ;; This actually needs the path and file name of the file to read.
$aRegExp = StringRegExp(FileRead($sFile), "\bXX\w*-\d\d\d-\w", 3);; Create a 0 based array using the RegExp
If NOT @Error Then
    $sOutFile = @DesktopDir & "\Output.txt"
    $hOut = FileOpen($sOutFile, 2)
    For $i = 0 To Ubound($aRegExp)-1
        FileWriteLine($hOut, $aRegExp[$i])
    Next
    FileClose($hOut)
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

The upgrade reverted code tags to defaults.

Thanks Jon.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

That is working great.

Thanks for your help.

Now i would like to be write in an output file any line containing a value.What should i change?

Share this post


Link to post
Share on other sites

That is working great.

Thanks for your help.

Now i would like to be write in an output file any line containing a value.What should i change?

If your regular expression is correct then what I gave you should do that. The very fact that you have asked says that your RegExp is not precise enough. Try to provide a few lines of sample input and what you need for the output and I'll try to fix the RegExp

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Hello,

I'm trying now to make an array of the text between '|' or '=' with lines starting with ':'

here is an exemple of the text i start with

FILE_TYPE=MULTI_PHYS_TABLE;

PART 'INDUCTOR'

PHYS_DES_PREFIX=L

PINCOUNT=2

CLASS=DISCRETE

ALLOW_CONNECT=TRUE

:PACK_TYPE |VALUE = PART_NUMBER |STATUS_1 |ECO_TYPE_1 |PART_NUMBER_2 |STATUS_2 |ECO_TYPE_2 |JEDEC_TYPE |HEIGHT |DESIGNATION ;

SMD0603 |BLM18EG601SN1D = IN0000136-A |C |RHS |IN0000136-A |O |DTY |0603 |38 |CHIP FERRITE BEAD 500MA 600 OHMS/100MHZ FOR HIGH SPEED SIGNAL

END_PART

END.

FILE_TYPE=MULTI_PHYS_TABLE;

PART 'DC_DCXBRICK_8'

PHYS_DES_PREFIX=U

PINCOUNT=8

CLASS=IC

ALLOW_CONNECT=TRUE

:PACK_TYPE |VALUE = PART_NUMBER |STATUS_1 |ECO_TYPE_1 |PART_NUMBER_2 |STATUS_2 |ECO_TYPE_2 |JEDEC_TYPE |HEIGHT |DESIGNATION ;

SQE48T |48/5V 20A = NA |NA |NA |SA0000310-A |C |FSC |SQE48T |FSC |407

END_PART

and i'de like to have my array like

VALUE

PACK_TYPE

PART_NUMBER

I thought of this but it is not working properly.

Do you know how to code regexp to match expression A and expression B for example?(i can't find a and function)

$aAttributs=StringRegExp(FileRead('temp_ptf.txt'),'(?<=\x3A).*[^\x7C]+', 3)
_ArrayDisplay($aAttributs,"attributs")

thanks

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I don't think you have provided actual values yet so I don't know if we are dealing with alpha, numeric or both so I just copied your example to a file named temp_ptf.txt.

This worked for me but you may need to change it depending on the actual contents.

#include<array.au3> ;; For _ArrayDisplay() only

$aAttributes = _PartsAttribs("temp_ptf.txt")
_ArrayDisplay($aAttributes, "Attributes")


Func _PartsAttribs($sStr)
   If FileExists($sStr) Then $sStr = FileRead($sStr)
   $sRegExp = ":\b(\w*)\s*\|\s*(\w*)\s*=\s*(\w*?)\s*\|"
   $aRegExp = StringRegExp($sStr, $sRegExp, 3)
   If NOT @Error Then
      Local $aRtn[Ubound($aRegExp)/3][3], $iCount = 0
      For $i = 0 To Ubound($aRegExp) -1 Step 3
         $aRtn[$iCount][0] = $aRegExp[$i+1]
         $aRtn[$iCount][1] = $aRegExp[$i]
         $aRtn[$iCount][2] = $aRegExp[$i+2]
         $iCount +=1
      Next
      Return $aRtn
   EndIf
EndFunc   ;<==> _PartDetails()
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks Geo

I found a solution but yours certainly working too:

$temp=StringRegExp(FileRead('temp_ptf.txt'),'(?<=\x3A).*(?=\s\x3B)', 3)
_FileWriteFromArray('temp_att.txt', $temp, 1)
$aAttributs=StringRegExp(FileRead('temp_att.txt'),'[^\x7C|\x3D|\x3B|\r|\s*]+', 3)
_ArrayDisplay($aAttributs,"attributs")

I'm still interesting to know how to use a AND fution in regexp (ex:I want to match pattern A and pattern B )

Thanks again for your help

Edited by sam71

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