Hello Ottar,
Historians believe that Tue, 17 Apr 2001 at 22:07 GMT +0200 was when,
Ottar Grimstad [OG] typed the following:
<snip>
OG> YES!! It works. Thank you!!
OG> There is one small hitch (that I can live very well with).
OG> If I have several groups and recipient are member of more
OG> than one, they might not use the correct template.
I think I'll pass on this one.
OG> And then the question is Why does it work? I dont know if it is
OG> within the scope of this list to teach regular expressions, but:
If I understood correctly, that's exactly what this list is designed
to do. Teach stuff that's too advanced for the beginner list.
OG> If I understand it correct, it is the %SETPATTREGEXP that makes
OG> things happen. It collects from %REGEXPBLINDMATCH and gives it
OG> further to the editor.
OG> Why the (?i)?
It makes the search case insensitive. That way <LIST>, <List>, <list>
and all other combinations are matched.
OG> I recognise the syntax (?(xxx)yyy|zzz) inside the %SETPATTREGEXP.
OG> If xxx is true then yyy is given to the editor, else zzz is given.
Yep.
OG> I recons that "?=.*?\<list\>.*?;;.*;;.*" reads the input from
OG> %TOLIST%CCLIST%BCCLIST and looks for the word the word <list>.
OG> But why the ".*?;;*;;.*" ?
So that list has to appear at the beginning. Remember, the string
being matched is generated by the following line:
%TOLIST%CCLIST%BCCLIST;;%QINCLUDE=""GROUP"";;%QINCLUDE=""INDIV""
So if for some reason your Group greeting or your Individual greeting
contains the string "<List>", the regexp won't be confused. This
regexp is still not foolproof, but it is less error prone with the
part you're asking about. Maybe the subpattern part below will help.
OG> If list is found then ".*;;(.*);;.*" is given to the editor, and
OG> this is taken from %QINCLUDE=""GROUP"" -
OG> Is ;; a common divider between elements?
Yes. You could change it to a different divider, but since Marck used
this one in his first Conditional Regexp, I got into the habit of
using the same one.
OG> Why is .* first without paranthesis, then with and then without?
OG> And after the | it is different - without, without and the with
OG> paranthesis.
The parentheses denote subpatterns. <see below>
OG> And why the "%SUBPATT="1"%SUBPATT="2" ?
You only want to extract certain information from the match.
Because of the parentheses above, the info is stored in either
subpattern 1 or 2. The %SUBPATT macros paste that information into
your template. In other words, this is how you "see" the results of
the match.
Remember the string we're looking at is generated by:
%TOLIST%CCLIST%BCCLIST;;%QINCLUDE=""GROUP"";;%QINCLUDE=""INDIV""
^^^^^^^^^^^^^^^^^^^^^^||^^^^^^^^^^^^^^^^^^^||^^^^^^^^^^^^^^^^^^^
See how there are three distinct sections? So the string "<list>" is
in the first part, we want only the second section. If "<list>" not
in the first part, we only want the third section. The parentheses
allow us to isolate the parts we're interested in using.
OG> Regular expressions seems like black magic, but I know it must be
OG> some logic to them.
The logic is extremely simple once you learn the language. The key is
to break down the regexp the way you did and try to understand the
bits to see what they do. Often we also play tricks to get things
working the way we want, in this case we manipulated the input string
so the matching pattern was easy to write. Other times we name Quick
Templates appropriately so a simple Regexp will choose between
multiple options. The only "magic" is deciding when to use one versus
the other. But that just comes with practice.
--
Thanks for writing,
Januk Aggarwal
Using The Bat! 1.51 under Windows 98 4.10 Build 2222 A
I've determined the momentum of my physics assignment so precisely
that it can be anywhere in the universe right now.
--
______________________________________________________
Archives : <http://tbtech.thebat.dutaint.com>
Moderators : <mailto:[EMAIL PROTECTED]>
Unsubscribe: <mailto:[EMAIL PROTECTED]>
You are subscribed as : [email protected]