Re: RegExp Question

2000-12-21 Thread Januk Aggarwal

Hello Stuart,

On  Thu, 21 Dec 2000  at  17:38:35 GMT + (which was 9:38 AM
where I live) witnesses say Stuart Tares typed:

> I though that it would have been a relatively easy thing to set up
> but am getting nowhere.

It takes a while.  You made a great attempt.

> I was thinking that the logic for the regexp
> would be:

> 1) Take all the text of the message

Correct.

> 2) Set everything up to the -=-=-=- as %SUBPATT0

Ah, this is your mistake.  %SUBPATT="0" is reserved for the entire
match.  So in your case you're matching everything including the sig.

> 3) Set (-=-=-=-\n\[.*\]\n\[.*\]\n) as %SUBPATT1

In your regexp, this is actually a higher subpattern.  I think it is
Subpattern 3.  Try it and see what number it takes before you get the
signature only.

> You could then set %QUOTES to the output of %SUBPATT0.  This is what
> I came up with:

> 
> %QUOTES="%SETPATTREGEXP=""(?is)((.*\n)*)(-=-=-=-\n\[.*\]\n\[.*\]\n)""%
> REGEXPBLINDMATCH=""%TEXT""%SUBPATT=""0"""
> 

That's good.  However, as I explained above, you're capturing one
subpattern to small.  Make it %SUBPATT=""1"" and it should work.

> This, however, gives me two copies of the text both with the
> footer/signature in it !  I am sure that I am missing something
> extremely obvious but I just can't see it.

Subpattern 0 is the entire text that is matched.  The two copies are
probably because you have forgotten to remove one of the %quotes.  You
only need the one line that you posted.

What you want is stored in SubPattern 1.  The subpatterns are what is
in brackets.  Count the number of opening brackets to find the
subpattern number.

BTW, you can simplify the regexp to:


%Quotes='%SETPATTREGEXP="(?is)(.*?)(\n-=-=-=-\n\[.*\])"%REGEXPBLINDMATCH="%TEXT"%SUBPATT="1"'


The newlines are matched by the '.' in '.*' because of the mode you are
using.  Knowing this, the end part of the sig can also be simplified
because '*' is greedy (see the end for discussion of greedy).

This regexp will give you everything up to the block:

-=-=-=-
[blah blah blah]
[blah blah blah]

Take a look at %SUBPATT="2" and you will see the entire signature.

Explanation of Greedy:

When you use a variable length repeat operator (like *), the largest
pattern that matches the regular expression will be used.  For
example, if you have:

> [some text] [ some other text]

Now use the regexp "\[(.*)\]" and look at subpattern 1.  You'll see:

> some text] [ some other text

If you don't want that behaviour, you have to make * ungreedy (The
same applies for all the repeat operators).  Ungreedy repeats will
match the smallest pattern that satisfies the rest of the regular
expression.  To make it ungreedy, add a '?' after the repeat operator.
Note that '?' has two meanings depending on context.
If we had used the regexp, "\[(.*?)\]", now you'd get:

> some text

 

-- 
Thanks for writing,
 Januk Aggarwal

 Using The Bat! 1.48f
 under Windows 98 4.10 Build   A 

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-21 Thread Brian Clark


Hello Januk, 

(JA == "Januk Aggarwal") [EMAIL PROTECTED] writes:

JA> That's good. However, as I explained above, you're capturing one
JA> subpattern to small. Make it %SUBPATT=""1"" and it should work.

Why are you using two sets of quotes around the value? I've seen
similar in some of the examples in the FAQ, I think.

What's different about %SUBPATT="1" (or for that matter,
%SUBPATT='1')?

Am I missing something?

--
...
 Brian Clark <[EMAIL PROTECTED]> PGP-KeyID: 0xE4D0C7C8
 Web Architect, Designer, and Programmer  Tel: 864.227.0750
 http://www.fusionwerks.com/  Fax: 864.942.7249
...



-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-21 Thread Januk Aggarwal

Hello Brian,

On  Fri, 22 Dec 2000  at  01:25:48 GMT -0500 (which was 10:25 PM
where I live) witnesses say Brian Clark typed:

> Why are you using two sets of quotes around the value? I've seen
> similar in some of the examples in the FAQ, I think.

> What's different about %SUBPATT="1" (or for that matter,
> %SUBPATT='1')?

> Am I missing something?

Excellent question.

There is no difference between single quotes and double quotes, it
just makes life easier to use a mix.  Hopefully the reason for this
will become clear.

The quotes (single and double) are delimiters that indicate the
boundaries for arguments to macros.  So =" or =' is the start of the
arguments, and a closing quote is the end.

When you have a macro that accepts arguments, the arguments can be
macros that need arguments.  Confused?  Perhaps an example is in
order.  Suppose we want to use a regular expression to clean up the
subject line.

%Subject="some regexp"

Where "some regexp" is something like:

%SETPATTREGEXP=":(.*)"%REGEXPBLINDMATCH="%OFULLSUBJ"%SUBPATT="1"

Now if you were to literally replace that regular expression line into
the %Subject macro, how is TB to know that you want all of it?
According to the rules, if we use:

%Subject="%SETPATTREGEXP=":(.*)"%REGEXPBLINDMATCH="%OFULLSUBJ"%SUBPATT="1""

TB thinks that the subject field should be filled with the value:
%SETPATTREGEXP=

That's not what you wanted.  One option around this is to double up
the inner quotation marks.  That's what Stuart had done, so I followed
suit.

The other option is to replace either the inner or outer argument (not
both) delimiters with single quotes.  So the macro looks like:

%Subject='%SETPATTREGEXP=":(.*)"%REGEXPBLINDMATCH="%OFULLSUBJ"%SUBPATT="1"'

Here, I replaced the outer quotes.  So the %Subject macro has an
opening delimiter =' and therefore it looks for the closing delimiter '
Note that you can make this almost arbitrarily complicated, you just
keep adding quotes.  So if you had a macro within a macro within a
macro that needed arguments, you'd need ', '', and '''.  Phew.

This seems a bit confusing when written out.  Try to work out what TB
sees, and ask any questions that may arise.

-- 
Thanks for writing,
 Januk Aggarwal

 Using The Bat! 1.48f
 under Windows 98 4.10 Build   A 

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-21 Thread Brian Clark


Hello Januk, 

(JA == "Januk Aggarwal") [EMAIL PROTECTED] writes:

JA> Hello Brian,

JA> On  Fri, 22 Dec 2000  at  01:25:48 GMT -0500 (which was 10:25 PM
JA> where I live) witnesses say Brian Clark typed:

>> Why are you using two sets of quotes around the value? I've seen
>> similar in some of the examples in the FAQ, I think.

>> What's different about %SUBPATT="1" (or for that matter,
>> %SUBPATT='1')?

>> Am I missing something?

JA> Excellent question.

JA> There is no difference between single quotes and double quotes, it
JA> just makes life easier to use a mix.  Hopefully the reason for this
JA> will become clear.



JA> This seems a bit confusing when written out.  Try to work out what TB
JA> sees, and ask any questions that may arise.

Not at all. Because I'm assuming %MACRO1="%MACRO2=\"%MACRO3\"" won't
cut it. From the languages I know, double quotes interpolate, single
quotes do not. But, I understood your explanation (snipped).

It just threw me off when you doubled-up double quotes like
%NAME=""value""

I thought you may have made a typo, and it appears that you did.

That's why I did the double-take. :)

--
...
 Brian Clark <[EMAIL PROTECTED]> PGP-KeyID: 0xE4D0C7C8
 Web Architect, Designer, and Programmer  Tel: 864.227.0750
 http://www.fusionwerks.com/  Fax: 864.942.7249
...

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-21 Thread Januk Aggarwal

Hello Brian,

On  Fri, 22 Dec 2000  at  02:34:58 GMT -0500 (which was 11:34 PM
where I live) witnesses say Brian Clark typed:

> Hello Januk, 


> It just threw me off when you doubled-up double quotes like
> %NAME=""value""

> I thought you may have made a typo, and it appears that you did.

No, it was intentional.  I wanted to be consistent with what the
original poster was using.  :-)

 

-- 
Thanks for writing,
 Januk Aggarwal

 Using The Bat! 1.48f
 under Windows 98 4.10 Build   A 

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-22 Thread Brian Clark


Hello Januk, 

(JA == "Januk Aggarwal") [EMAIL PROTECTED] writes:

>> It just threw me off when you doubled-up double quotes like
>> %NAME=""value""

>> I thought you may have made a typo, and it appears that you did.

JA> No, it was intentional.  I wanted to be consistent with what the
JA> original poster was using.  :-)

OK, now I'm confused. I tend to get that way with plenty of things, as
some of you *cough* Marck, Allie *cough* *cough* know.

I'm assuming Stuart borrowed from the "Strip PGP Signatures" example
in the Macros section of the FAQ:

[one line]
%quotes="%SETPATTREGEXP=""(?is)(^-BEGIN PGP 
SIGNED.*?\n(Hash:.*?\n)?\s*)?(.*?)(^(-*?\s*?--
\s*\n|_{40,}\s*\n|-BEGIN PGP 
SIGNATURE)|\z)""%REGEXPBLINDMATCH=""%text""%SUBPATT=""3"""
[one line]

Could you tell me why there needs to be two sets of double quotes
around the regular expression:

%SETPATTREGEXP=""(?is)(^-BEGIN PGP SIGNED.*?\n(Hash:.*?\n)?\s*)?(.*?)(^(-*?\s*?--
\s*\n|_{40,}\s*\n|-BEGIN PGP SIGNATURE)|\z)""

and:

%REGEXPBLINDMATCH=""%text""

and this:

%SUBPATT=""3""

--
...
 Brian Clark <[EMAIL PROTECTED]> PGP-KeyID: 0xE4D0C7C8
 Web Architect, Designer, and Programmer  Tel: 864.227.0750
 http://www.fusionwerks.com/  Fax: 864.942.7249
...

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-22 Thread Stuart Tares

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Januk,

On Thu, 21 Dec 2000, at 13:15:21 (which was 21:15 where I live) you
wrote :

>> 2) Set everything up to the -=-=-=- as %SUBPATT0

JA> Ah, this is your mistake. %SUBPATT="0" is reserved for the entire
JA> match.  So in your case you're matching everything including the
sig.

Ahh!  Now that I have gone back and re-read the help pages, this
becomes clear.  I thought I had tried everything but obviously not
:-)

JA> BTW, you can simplify the regexp to:
JA>
JA> 
JA>
%Quotes='%SETPATTREGEXP="(?is)(.*?)(\n-=-=-=-\n\[.*\])"%REGEXPBLINDMAT
CH="%TEXT"%SUBPATT="1"'
JA> 

I was going to try to simplify the regexp once I had got it working,
so thanks very much for doing it for me.  I was working on the
premise of making sure that I grabbed everything and then simplify
it.

Thanks very much for the help.  I have found this group to be very
useful in my learning of TB and hope that I can help others in the
future.

Stuart

- --
A conclusion is simply the place where you got tired of thinking.

-BEGIN PGP SIGNATURE-
Version: PGP 6.5i
Comment: Digitally signed for sender verification.

iQA/AwUBOkMOLHjB/5h2FIaGEQKxzgCffbrfHyUXF+LwEE5dAR/whCZ7rZ0An2H2
F9dM2hjE2RNn0YudPwo5Tq/6
=grya
-END PGP SIGNATURE-

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-22 Thread Januk Aggarwal

Hello Brian,

On  Fri, 22 Dec 2000  at  03:16:56 GMT -0500 (which was 12:16 AM
where I live) witnesses say Brian Clark typed:

> OK, now I'm confused. I tend to get that way with plenty of things, as
> some of you *cough* Marck, Allie *cough* *cough* know.

 No problem.

> ... from the "Strip PGP Signatures" example
> in the Macros section of the FAQ:

> [one line]
> %quotes="%SETPATTREGEXP=""(?is)(^-BEGIN PGP 
>SIGNED.*?\n(Hash:.*?\n)?\s*)?(.*?)(^(-*?\s*?--
> \s*\n|_{40,}\s*\n|-BEGIN PGP 
>SIGNATURE)|\z)""%REGEXPBLINDMATCH=""%text""%SUBPATT=""3"""
> [one line]

> Could you tell me why there needs to be two sets of double quotes
> around the regular expression:

> %SETPATTREGEXP=""(?is)(^-BEGIN PGP SIGNED.*?\n(Hash:.*?\n)?\s*)?(.*?)(^(-*?\s*?--
> \s*\n|_{40,}\s*\n|-BEGIN PGP SIGNATURE)|\z)""

> and:

> %REGEXPBLINDMATCH=""%text""

> and this:

> %SUBPATT=""3""

This is because these three macros are arguments to the %Quotes macro,
and the delimiters for the %QUOTES macro is single double quotes.
Therefore a different delimiter needs to be used, and so double double
quotes were used.
 

-- 
Thanks for writing,
 Januk Aggarwal

 Using The Bat! 1.48f
 under Windows 98 4.10 Build   A 

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-22 Thread Brian Clark


Hello Januk, 

(JA == "Januk Aggarwal") [EMAIL PROTECTED] writes:

>> ... from the "Strip PGP Signatures" example
>> in the Macros section of the FAQ:

>> [one line]
>> %quotes="%SETPATTREGEXP=""(?is)(^-BEGIN PGP 
>SIGNED.*?\n(Hash:.*?\n)?\s*)?(.*?)(^(-*?\s*?--
>> \s*\n|_{40,}\s*\n|-BEGIN PGP 
>SIGNATURE)|\z)""%REGEXPBLINDMATCH=""%text""%SUBPATT=""3"""
>> [one line]

>> Could you tell me why there needs to be two sets of double quotes
>> around the regular expression.



JA> This is because these three macros are arguments to the %Quotes macro,
JA> and the delimiters for the %QUOTES macro is single double quotes.
JA> Therefore a different delimiter needs to be used, and so double double
JA> quotes were used.
 
OK, then this should be equivalent to the original, right?

[one line]
%quotes='%SETPATTREGEXP="(?is)(^-BEGIN PGP 
SIGNED.*?\n(Hash:.*?\n)?\s*)?(.*?)(^(-*?\s*?--
\s*\n|_{40,}\s*\n|-BEGIN PGP SIGNATURE)|\z)"%REGEXPBLINDMATCH="%text"%SUBPATT="3"'
[one line]

I should probably just be trying this myself..

--
...
 Brian Clark <[EMAIL PROTECTED]> PGP-KeyID: 0xE4D0C7C8
 Web Architect, Designer, and Programmer  Tel: 864.227.0750
 http://www.fusionwerks.com/  Fax: 864.942.7249
...

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-22 Thread Stuart Tares

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Januk,

On Fri, 22 Dec 2000, at 00:04:59 (which was 08:04 where I live) you
wrote :

JA> No, it was intentional.  I wanted to be consistent with what the
JA> original poster was using.  :-)

Who wanted to be consistent with all the examples that he had seen.
Thanks once again, Januk, for a clear and concise explanation of why
it is like this.

Stuart

- --
And now for something completely different...

-BEGIN PGP SIGNATURE-
Version: PGP 6.5i
Comment: Digitally signed for sender verification.

iQA/AwUBOkMUOHjB/5h2FIaGEQKAiwCg3y+X+E/tQ/d9uoJAsMq+a7qyexEAoLgp
puOgF8oK60HI+yGuocVwkci+
=EBDU
-END PGP SIGNATURE-

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org





Re: RegExp Question

2000-12-22 Thread Januk Aggarwal

Hello Brian,

On  Fri, 22 Dec 2000  at  03:36:42 GMT -0500 (which was 12:36 AM
where I live) witnesses say Brian Clark typed:



JA>> ... the delimiters for the %QUOTES macro is single double quotes.
JA>> Therefore a different delimiter needs to be used, and so double double
JA>> quotes were used.
 
> OK, then this should be equivalent to the original, right?


Barring any typos I'm not seeing, that is correct.

> I should probably just be trying this myself..

Feel free to experiment.  I have a QT called 'tester'.  Any time I
want to test some template fragment, I put it in there, then from an
editor I can manually apply the template quickly.  It makes efficient
development easy.
 

-- 
Thanks for writing,
 Januk Aggarwal

 Using The Bat! 1.48f
 under Windows 98 4.10 Build   A 

-- 
--
View the TBUDL archive at http://tbudl.thebat.dutaint.com
To send a message to the list moderation team double click here:
   
To Unsubscribe from TBUDL, double click here and send the message:
   
--

You are subscribed as : archive@jab.org