Internet technologies and communication software



Problem with script regex and match ...
Search  Users  Rules 
Close
Login:
Password:
Forgot your password?
Register
Login
 
Pages: 1
RSS
Problem with script regex and match ..., Templates and Macro
 
hello,

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
Email: beam@blabla.com
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±
%SetPattRegExp="(?is)Product:\s(.*?)\n(.*)"%-
%RegExpBlindMatch="%_SFPI_SearchText"%-
%_SFPI_Result='%SubPatt="1"'%-
%_SFPI_SearchText='%SubPatt="2"'%-
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: http://cgi.silverstones.com/library.php#greet_all_recipients
__________________________________
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:

Code
%SETPATTREGEXP="(?i-s)(^Product :\s)(.*)(\n|\z)(\1(.*)\3)?(\1(.*)\3)?"%-
%REGEXPBLINDMATCH="%TEXT"%-
%SUBPATT(2)%-
%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!,
K_S!,
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.07.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):
Code
%SETPATTREGEXP="(?is)(^Name :\s)(.*?)\n%-
(.*?\1(.*?)\n)?%-
(.*?\1(.*?)\n)?%-
(.*?\1(.*?)\n)?%-
(.*?\1(.*?)\n)?%-
(.*?\1(.*?)\n)?%-
"%-
%REGEXPBLINDMATCH="%TEXT"%-
%SUBPATT(2)%-
%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:
Code
%SETPATTREGEXP="(?is)(^Quantity : )(.*?)\n%-
(^Name : )(.*?)\n%-
(^Reference : )(.*?)\n%-
(^Price : )(.*?)\n%-
((^reduced to : )(.*?)\n)?%-
(^total line : )(.*?)\n%-
(.*?\1(.*?)\n\3(.*?)\n\5(.*?)\n\7(.*?)\n(\10(.*?)\n)?\12(.*?)\n)?%-
(.*?\1(.*?)\n\3(.*?)\n\5(.*?)\n\7(.*?)\n(\10(.*?)\n)?\12(.*?)\n)?%-
(.*?\1(.*?)\n\3(.*?)\n\5(.*?)\n\7(.*?)\n(\10(.*?)\n)?\12(.*?)\n)?%-
"%-
%REGEXPBLINDMATCH="%TEXT"%-

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)

%IF:'%SUBPATT(14)'<>'':'
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)
'%-

%IF:'%SUBPATT(22)'<>'':'
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)
'%-

%IF:'%SUBPATT(30)'<>'':'
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)
'%-

Quote
Tell me also How can I thank U

<voice mode='Terminator' ON>No problemo<voice OFF>
 
K_S!
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 http://www.jetable.org/en/index in order to avoid spam) that will give me also the possibility to send U a small "thank U". ;)
Edited: lemo nico - 17.07.2009 21:31:38
 
lemo nico, my email adress: konrad_sz@wp.pl

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
Users browsing this topic (1 guests)