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.
views:
47answers:
2
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
2010-06-02 15:25:54
Provided the language supports negative lookahead. (e.g. GNU grep doesn't http://www.greenend.org.uk/rjk/2002/06/regexp.html)
Stephen
2010-06-02 15:29:12
hmmm, how does that fit with my existing: `[^0]\\swarnings?(?!\\.|\\w)`
iamnotmad
2010-06-02 15:32:23
replace the .+ with your existing code
seanizer
2010-06-02 15:35:40
@Stephen: True. OP didn't specify language.
Robusto
2010-06-02 15:48:25
@seanizer: Yes. Edited to make it crystal clear to OP.
Robusto
2010-06-02 15:49:11
that does not seem to work (I took out my extra backslashes, sorry about that). No love though.
iamnotmad
2010-06-02 16:08:46
@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
2010-06-02 17:01:34
+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
2010-06-02 15:30:54
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
2010-06-02 16:39:02
+1 - thats +0.3 for the regex approach itself and +0.7 for the sane/pragmatic suggestion in the last paragraph ;-)
Tomalak
2010-06-02 17:04:42