Pages: 1
Problem with script regex and match ..., Templates and Macro

I use 100 times a day such a template:
%SETPATTREGEXP="(?i-s)^BProduct :\s(.*)$|\z"%-%REGEXPBLINDMATCH="%text"%-

in order to make automatic answer of my forms like:

Original email from a form:

Contact: Mr beam
Product : book of linux
Product : book of window

My answer is:

Dear Mr beam, please find enclose more information about the book of linux.

And I would like to have:

Dear Mr beam, please find enclose more information about the book of linux and the book of window.

That forI am using a template like  
%SETPATTREGEXP="(?i-s)^BProduct :\s(.*)$|\z"%-%REGEXPBLINDMATCH="%text"%-

My problem is: how can I configure my template in order to get the second chain of Product “book of window“, indeed since it has the same name as the first chain “Product :” book of linux I always get only the first regex (book of linux) and I can not get the book of window In my answer.

How do I do this ?

Many thanks in advance.
You need a recursive quick template: a template that calls itself.
Without writing the template for you (otherwise there'd be no challenge left for you, would there?) here are some things, you'll need to address for this.
Call your QT SearchForProductItems, that's a nice distinctive name.
Use the %_SFPI_ prefix for all parameters, like %_SFPI_Counter, %_SFPI_Result, %_SFPI_SearchText, %_SFPI_Output, etc. This way you don´t have to take care that you´re using parameters with the same name as the template that calls the first QT.
First thing your template has to do is check whether you´re running it for the first pass or not, that´s why you use a counter. The first pass sets your counter to 1 and sets your searchtext to equal %Text.
Next your QT extracts the first product, enters that value in the Result parameter and sets the the rest of your searchtext as yur new searchtext.
Something like this±
Now you check whether your result is empty or not. If it's empty then you stop processing the text. If it's not empty then you add the result to your output parameter and call the QT again. As it isn't the first time your QT is called, your counter has a value and so your template will 'know' that you've got a truncated searchtext and will use that.

I hope this makes things a bit clear.
An example of a recursive template can be found here:
I'm just a user of The Bat! I don't work for Ritlabs.
Thanks a lot for the tip,

I ll try to write the template and inform you about the result (in fact it is a big challenge for me since I am     a beginner :|  in QT)  .

one more time thanks a lot.  
 :cry:  :cry:  :cry:  :cry:  :cry:  :cry:  :cry:

Hello  Roelof Otten,

I have tried, tried, tried but din not managed  :oops:

The challenge is too big for me  :cry:  
I'm a bit short on time currently, so you've got to wait. But maybe somebody else feels like having a go at it.
I'm just a user of The Bat! I don't work for Ritlabs.
I think recursive template is too complicated solution. Regexp is faster. If You have only a few lines with 'Product : sth' in email (for example no more than 10) You could use this regexp:

%SETPATTREGEXP="(?i-s)(^Product :\s)(.*)(\n|\z)(\1(.*)\3)?(\1(.*)\3)?"%-
%IF:'%SUBPATT(5)'<>'':' and %SUBPATT(5)'%-
%IF:'%SUBPATT(7)'<>'':' and %SUBPATT(7)'%-

This will catch three 'Product' lines, but I hope You see how it works and know how to expand this.
I hate www forums... Code from my previus message is broken. Before each number in %SETPATTREGEXP should be an \\ (backslash).
thanks a lot :)
I try it and say you the way its go   ;)  
Roelof Otten!,
I try and retry your proposal, and try also to modify it (I am an inexperienced Templatemaker  :oops: ) but I only managed to get the first product  :cry:  :cry:  :cry:

In fact I am working with a Webshop and I get the order in emails. I rewrite each order in invoice and lose too much time.
My dream: TheBat get the info and put print it with templates.

The Email looks like that:

Quantity : 2
Name :  The Bat! Pro Edition V9.9
Reference : TBP9.9
Price : $45.00
reduced to : $39.00    
total line : $78,00

Quantity : 1
Name :  The Bat! Voyager V9.9
Reference : TBV9.9
Price : $15.00
reduced to : $9.00    
total line : $9.00

Quantity : 1
Name :  The Bat! Private Disk V9.9
Reference : TBPD9.9
Price : $19.00
total line : $19.00

I have been trying and trying but without success :cry:

Hopping a programming god could help me here :!:
Edited: lemo nico - 14 July 2009 13:56:16
Lemo nico, I don't understand, in Your first message email format was different and my regexp worked. Maybe there are some spaces (at the begining of the line) or empty lines in real emails?

If e-mails looks like in Your newest message, then a simple template to catch names of products could looks like that (this will catch max 7 names):
%SETPATTREGEXP="(?is)(^Name :\s)(.*?)\n%-
%IF:'%SUBPATT(4)'<>'':' and %SUBPATT(4)'%-
%IF:'%SUBPATT(6)'<>'':' and %SUBPATT(6)'%-
%IF:'%SUBPATT(8)'<>'':' and %SUBPATT(8)'%-
%IF:'%SUBPATT(10)'<>'':' and %SUBPATT(10)'%-
%IF:'%SUBPATT(12)'<>'':' and %SUBPATT(12)'%-
%IF:'%SUBPATT(14)'<>'':' and %SUBPATT(14)'%-
KOOOL !!! KS you are the best ! :)
how can I thank U ????

:{}  :{}  :{}  :{}  :{}
oh oh I have talk to fast  :cry:

in fact with this template I get all the Name

so for my exemple I get

The Bat! Pro Edition V9.9
The Bat! Voyager V9.9
The Bat! Private Disk V9.9

but what is about the other field ?

Quantity :
Reference :
Price :
reduced to :
total line :


I suppose we should here mare some other SUBPATT(...)

I have tried to mix the progammation, change the line and so on, but without success :evil:

I know it a hard challenge but the possibility of such a template is really a dream !!!

Tell me also How can I thank U, send me your Email for ex. because U R really my saviour  :{}
Try this regexp:
%SETPATTREGEXP="(?is)(^Quantity : )(.*?)\n%-
(^Name : )(.*?)\n%-
(^Reference : )(.*?)\n%-
(^Price : )(.*?)\n%-
((^reduced to : )(.*?)\n)?%-
(^total line : )(.*?)\n%-
first Quantity %SUBPATT(2)
first Name %SUBPATT(4)
first Reference %SUBPATT(6)
first Price %SUBPATT(8)
%IF:'%SUBPATT(9)'<>'':'first reduced %SUBPATT(11)'
first total %SUBPATT(13)
second Quantity %SUBPATT(15)
second Name %SUBPATT(16)
second Reference %SUBPATT(17)
second Price %SUBPATT(18)
%IF:`%SUBPATT(19)`<>``:`second reduced %SUBPATT(20)`
second total %SUBPATT(21)
third Quantity %SUBPATT(23)
third Name %SUBPATT(24)
third Reference %SUBPATT(25)
third Price %SUBPATT(26)
%IF:`%SUBPATT(27)`<>``:`third reduced %SUBPATT(28)`
third total %SUBPATT(29)
fourth Quantity %SUBPATT(31)
fourth Name %SUBPATT(32)
fourth Reference %SUBPATT(33)
fourth Price %SUBPATT(34)
%IF:`%SUBPATT(35)`<>``:`fourth reduced %SUBPATT(36)`
fourth total %SUBPATT(37)

Tell me also How can I thank U
<voice mode='Terminator' ON>No problemo<voice OFF>
thanks a lot one more time  ♥♥♥♥♥♥♥♥♥♥

I have tried it, it works nearly perfect  :D.
my last problem: I get always some "█" (tabs)  ant the invoices look horrible :evil: :

first Quantity █x
first Name___xxxxxx
first Reference________xxxxxx
Optionen :      
first Price
first reduced      
Steuern :_______xxxxxx
first total______xxxxxx Ђ

second Quantity_______x
("_" represent the different distances between the felds).

since I can not put tabs in the template in order to recognise the fields, I do not know how can I get ride of them :(

Till know I use the folowing template:
%SETPATTREGEXP="(?i-s)^Menge :\s(.*)$|\z"%-%REGEXPBLINDMATCH="%text"%-%SUBPATT="1"%-
in order to get the result of the field "Menge :"

in fact the originality the fields look like:

Menge : 2
Name :  Thebat Pro V9
Katalognummer : TBV9
Optionen :      Voyager
Preis : 9,50 Ђ
Herabgesetzt auf :    4,50 Ђ  
Steuern :       1,44 Ђ
Zwischensumme : 9,00 Ђ

for your info here is the translation German <-> english:
Menge <-> Quantity
Herabgesetzt auf <-> reduced
Steuern <-> Tax
Zwischensumme <-> first total

And I need to get the following result in order to print it in only one page even if 20 products are ordered:

"Menge" "Katalognummer" "Name"
"Optionen (if present)
"Preis" "Herabgesetzt auf" (if present) "Steuern" "Zwischensumme"

2 x TBV9 Thebat Pro V9
Option : Voyager
Preis stück : 9,50 Ђ, Herabgesetzt auf : 4,50 Ђ, inklusive Steuer : 1,44 Ђ, Zwischensumme : 9 ,00 Ђ

so that we don t need 20 pages to print the order ;)

With your template the field "Optionen :" block the template to extract the name of the product...

I would like to send U the Email I get in order to show U how they look like ?

Please write me your Email in your profile (you can use for this in order to avoid spam) that will give me also the possibility to send U a small "thank U".  ;)
Edited: lemo nico - 17 July 2009 21:31:38
lemo nico, my email adress:

I think this (or any) forum is not the best place to present templates: sometime empty lines, important spaces or new lines disappears in html.

Please, send me some examples of Your orders, and tell me exactly which fields are optional and how much orders in one mail could be (if more than 10 I would recommend template with a 'loop' macro from XMP or MyMacros plugin).
Pages: 1