[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Regular Expression Problem

On Wed, May 21, 2003 at 02:20:46PM -0700, Mike Fedyk wrote:
> > > set reply_regexp = "^([[]?(re|aw|fwd|fw):[ \t]+)*(.*[]])?)?"
> > 
> > Wouldn't you need to escape the [] characters? Try: \[ and \].
> No, strangely enough, mutt's regexes don't like \[ and \], but the do like
> [[] and []].

That'd be "match a character class that contains [" for the first one and
the second one is "match a character class that contains ]". Hmm.

For my own sanity I'm going to write out what the above matches.

^	Start with		 
(	a group that contains
[[]	an optional character class of "["
(	then another group that contains
re|aw|fwd|fw	one of: re or aw or fwd or fw
)	end of the "re" group
:	followed by ":"
[ \t]	then a character class that matches AT LEAST one space or tab
)*	end of the "[re: " bit. Which may appear zero or more times.
(	new group that is optional and contains
.*	zero or more characters
[]]	followed by a required ]
)	end of the group which contains "any character and ends with ]"
)	end a group that...there's no start for this group!

Ok, you have more close than open brackets. This will be a problem. Also:
your entire regular expression is optional...
Shouldn't there be at least some part that's required? Like "at least re
or aw or fwd or fw"...For that you'd add another group. In very simplied
	an optional [ 
	at least one "re|fwd|fw" 
	with an optional ending ]

> Won't the regular expressions stop once it finds a match?  So if it matches
> on:

regular expressions are greedy. They will try to match as much as they
possibly can.

> [fwd: abc
> with "^([[]?(re|aw|fwd|fw):[ \t]+)*"
> won't it stop trying to match if you have:
> "^([[]?(re|aw|fwd|fw):[ \t]+)*|(.*[]])?)$"
> hmm?  So it still wouldn't match the last "]". :(

Why do you have the "or" in there?

> I'm trying to match two outer parts of a string, without matching the center
> part between the two outter parts.  Any new ideas would be helpful.

I usually find and end part with something like this: 
i.e. as long as you're NOT my character class keep going. (must find at
least one character that is not your character class -- which creates the

Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]

Reply to: