Jump to content

Help Parsing string


John117
 Share

Recommended Posts

hey guys, I need to pull a code from a couple thousand emails I have. The code replaces where you see 'X' in the below example. The location of the code is unknown as far as character length is concerned. The following code worked for another project I had, So I am hoping this one will as well. Please help if you can . . .

#include <file.au3>
#include <IE.au3>
#include <Array.au3>
HotKeySet("{ESC}", "_Quit")
HotKeySet("{NUMPAD1}", "_Run1")

$oIE = _IEAttach ("The Email With The Code")
$sHTML = _IEBodyReadHTML ($oIE)

While 1
Sleep(50)
WEnd

Func _Run1()
;CODE: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX Behold ;This is the string I am looking to pull only the XXX-XXX stuff from. It includes code at the start of it and space and behold at the end. 
$aNameArray = StringRegExp($sHTML, " ([[:alnum:]]*?)\-([[:alnum:]]*?)X", 3) ;This code worked with a similar project with a unknown email address
;$aNameArray = StringRegExp($sHTML, "CODE: ([[:alnum:]]*?) Behold", 0) ;I tried this adaptation
MsgBox(4096, "Working", $aNameArray[0])
;MsgBox(4096, "Working", $sHTML)
EndFunc ;==>Run

Func _Quit()
Exit
EndFunc ;==>Quit
Edited by Hatcheda
Link to comment
Share on other sites

How about the expression "CODE: ([0-9\-]+?) Behold". See if that returns the code.

so try this?

$aNameArray = StringRegExp($sHTML, "CODE: ([0-9\-]+?) Behold", 3)

or

$aNameArray = StringRegExp($sHTML, "CODE: ([0-9\-]+?) Behold", 0)

Link to comment
Share on other sites

ok, as written does not work. . .

#include <file.au3>
#include <IE.au3>
#include <Array.au3>
HotKeySet("{ESC}", "_Quit")
HotKeySet("{NUMPAD1}", "_Run1")

$oIE = _IEAttach ("The Website")
$sHTML = _IEBodyReadHTML ($oIE)

While 1
    Sleep(50)
WEnd

Func _Run1()
    ;CODE: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX          Behold
;$aNameArray = StringRegExp($sHTML, " ([[:alnum:]]*?)\-([[:alnum:]]*?)X", 3) ;This code worked with a similar project with a unknown email address




$aNameArray = StringRegExp($sHTML, "CODE: ([0-9\-]+?) Behold", 0) 
;$aNameArray = StringRegExp($sHTML, "CODE: ([[:alnum:]]*?)          Behold", 0) ;I tried this adaptation
MsgBox(4096, "Working", $aNameArray)
;MsgBox(4096, "Working", $sHTML)
EndFunc ;==>Run
;_FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite = 0])
Func _Quit()
Exit
EndFunc ;==>Quit
_StringBetween()
Link to comment
Share on other sites

I was thinking something like this:

Func _Run1()
    $aNameArray  = _StringBetween($sHTML, 'CODE:', 'Behold');Finds all occurences of "CODE: [i]SomeString [/i]Behold"
    If not IsArray($aNameArray) Then Return
    For $i=0 to ubound($aNameArray) -1
        $ReplacementString = 'CODE: Behold'  ;Whatever your Static string to place is
        If StringInStr($sHTML, $aNameArray[$i]) Then StringReplace($sHTML, $aNameArray[$i], $ReplacementString)
    Next
EndFunc

This should work if you are either removing the XXX stuff or replacing it with the same string each time

Edited by Varian
Link to comment
Share on other sites

ok, I can get it to show the first two now, but not three

$aNameArray = StringRegExp($sHTML, "CODE: ([[:alnum:]]*?)\-([[:alnum:]]*?)-", 3)

MsgBox(4096, "Working", $aNameArray[0] & "-" & $aNameArray[1])

Edit:

Checking previous post . . . .

Edited by Hatcheda
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...