AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

I need help with RegExMatch
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
nick



Joined: 24 Aug 2005
Posts: 504
Location: Berlin / Germany

PostPosted: Mon Nov 16, 2009 7:43 am    Post subject: Reply with quote

Some working example (at least for me):
Code:
#NoEnv
MailBody =
(Join`r`n
my company
221, Rev Road
1234 Swiss Town
Eine neue Bestellung ist eingetroffen.
 
Bestell-Informationen
Bestellnummer: xxxx
Bestelldatum: Wednesday, 11 November 2009
Bestellstatus:
 
Ihre Informationen
Rechungsadresse
Firma:
Name: Jane Doe
Adresse : 123, Some Road

 
Stadt : Swiss village
Postleitzahl : 4321
Land : CHE
Telefon : 012 345 67 89
Fax :
Email : jane.doe@example.com
 Lieferadresse
Firma:  Acme inc.
Name : Jane Doe
Adresse : 123, Some other Road
Apt. 6
 
Stadt : Big Swiss town
Postleitzahl : 4567
Land : CHE
Telefon : 039 345 67 89
Fax :
 
 
 
 
Bestellte Produkte
Anzahl Name Artikel-Nr. Preis Summe
1 widget xy-01-001 64.45 chf 64.45 chf
2 widgets xy-01-002aa 34.34 chf 34.34 chf
)
; Initialize items variables
R_ := R_Firma := R_Name := R_Adresse := R_Stadt := ""
L_ := L_Firma := L_Name := L_Adresse := L_Stadt := ""
B_ := "", B_Counter := 0
P := 1
; Search for items -------------------------------------------------------------
RXAdresse := "\s*Firma\s*:\s(?P<Firma>\V*)\s*Name\s*:\s*(?P<Name>\V*)\s*Adresse\s*:\s*(?P<Adresse>\V*\R?\V*)\s*Stadt\s*:\s*(?P<Stadt>\V*)"
RXArtikel := "m)^(?P<Anzahl>\d+).*?(?P<ArtikelNr>xy-\d+-\w+)"
Mail := MailBody ; should be Clipboard
P := RegExMatch(Mail, "Rechungsadresse" . RXAdresse, R_, P)
P := RegExMatch(Mail, "Lieferadresse" . RXAdresse, L_, P ? P + StrLen(R_) : 1)
If P := InStr(Mail, "Bestellte Produkte", 1, P ? P + StrLen(L_) : 1) {
   While P := RegExMatch(Mail, RXArtikel, B_, P + StrLen(B_)) {
      B_Anzahl%A_Index% := B_Anzahl
      B_ArtikelNr%A_Index% := B_ArtikelNr
      B_Counter := A_Index
   }
}
; Remove trailing linefeeds from addresses
R_Adresse := RegExReplace(R_Adresse, "\R+$")
L_Adresse := RegExReplace(L_Adresse, "\R+$")
; Show variables
Msg := "Rechungsadresse:`n"
     . "Firma:  " . R_Firma . "`n"
     . "Name:  " . R_Name . "`n"
     . "Adresse:  " . R_Adresse . "`n"
     . "Stadt:  " . R_Stadt . "`n`n"
     . "Lieferadresse`n"
     . "Firma:  " . L_Firma . "`n"
     . "Name:  " . L_Name . "`n"
     . "Adresse:  " . L_Adresse . "`n"
     . "Stadt:  " . L_Stadt . "`n`n"
     . "Bestellte Produkte = " . B_Counter . "`n"
Loop, % B_Counter
   Msg .= B_Anzahl%A_Index% . " - " . B_ArtikelNr%A_Index% . "`n"
MsgBox, % Msg
Return

_________________
nick

denick @ http://de.autohotkey.com/forum/
Back to top
View user's profile Send private message
TalksWithComputers



Joined: 16 Aug 2009
Posts: 20

PostPosted: Mon Nov 16, 2009 2:58 pm    Post subject: Reply with quote

Anonymous wrote:
TalksWithComputers wrote:
I always get an error message when trying to run the while loop.
Are you using the most recent release of AHK?

No, I ain't... yet Embarassed
Nick wrote:
Some working example

Lovely.
I've tested it on various order mails and it works! So cool! You just made someone very happy!

Phew...

Now for using the stuff in the real world... But I'll bug someone else with this.
Thanks again!
Boris
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group