On Sep 14, 2006, at 7:24 PM, Alan Storm wrote:

On Thu, 14 Sep 2006, Brian Drumm wrote:

I think this should be simple, but I must have been dancing all around
the answer for the last couple of hours.

I want to match any single occurrence of the character ">" at the
beginning of a line, but want to ignore any occurences where there are
multiple instances of the same character in sequence, like ">>>".

This should cover you

^>{1}[^>]

Breaking it down
=====================

^>{1} #any line that starts with a ">", repeated one time ...

The {1} is functionally useless (1 occurrence is the default)


[^>]  #folled by a single occurance of any
      #character which is not a ">"


Edge Case
=====================

The only thing this won't cover is a ">", on the final line of your file,
all by itself.

... And that's where the negative lookahead assertion comes in
handy ... but there's another trick, for when you're using
older regex engines:

        ^>([^>]|$)

^     : beginning of the line
>     : the character '>'
( | ) : one of these items:
[^>]      : not the character '>'
$         : the end of the line

Because the end of the document is also the end of
a line, it'll match, and the end of the line qualifies
as not a '>'.


(I know, I could use (?:) to save memory, and \Z to
match only at the end of the document, but I'm trying to
be backwards compatible here)


-----
Joe Hourcle

--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to