tags:

views:

47

answers:

2

I actually want to skip matches on lines that begin with "..." in this case. I already have: [^0]\\swarnings?(?!\\.|\\w) so I need to keep that functionality and add the don't match warning on lines starting with "..." Thanks! edit: I'm using javascript.

A: 

Try

^(?!\.+).+$

or, if you need to match 3 dots exactly,

^(?!\.{3}).+$

Edited to show case with OP's current regex:

^(?!\.{3})[^0]\\swarnings?(?!\\.|\\w)$
Robusto
Provided the language supports negative lookahead. (e.g. GNU grep doesn't http://www.greenend.org.uk/rjk/2002/06/regexp.html)
Stephen
hmmm, how does that fit with my existing: `[^0]\\swarnings?(?!\\.|\\w)`
iamnotmad
replace the .+ with your existing code
seanizer
@Stephen: True. OP didn't specify language.
Robusto
@seanizer: Yes. Edited to make it crystal clear to OP.
Robusto
that does not seem to work (I took out my extra backslashes, sorry about that). No love though.
iamnotmad
@Robusto: This (i.e. your sample #3) does not work because it does not allow characters between the start-of-line condition and the actual match.
Tomalak
+1  A: 

If you use a language supporting infinitely sized lookbehinds (like .NET), you can use

(?<!^\.\.\..*)yourterm

If you cannot use this, but know that there may be only one match of your expression per line, you could find those by using

^(?!\.\.\.).*(yourterm)

This will actually match the whole start of the line, but have the term you are interested in in a capturing group.

If you can have multiple matches per line, you can not easily achieve this with only one regex, I think.

In any case, it might be easier to use ^(?!\.\.\.).* to first get rid of all lines starting with ... and start another run on these to obtain your matches.

Jens
Although many *implementations* of various languages may impose a limit on the size of a look-behind, I doubt that any language itself imposes such a limit.
William Pursell
+1 - thats +0.3 for the regex approach itself and +0.7 for the sane/pragmatic suggestion in the last paragraph ;-)
Tomalak