Reputation: 3164
I want to find all the commented lines that don't end with period(.)
.
I have this expression //[A-Za-z0-9-\(\)\.,\-\\/ !\:_"]
but I don't know how to make it detect only lines that don't have periond(.)
before EOL.
I'm using C++ so comments start with //
. For example I want this string to be matched:
// My comment here
but not this one:
// My comment here.
Anyone can help?
Upvotes: 1
Views: 691
Reputation: 785128
This negative lookbehind based regex should work for you:
(?m)^//.*$(?<!\.)
OR negative lookahead based:
(?m)^//(?!.*\.$).*$
Upvotes: 2
Reputation: 5268
No need for negative lookbehind or lookahead, keep it simple:
^\/\/(.*[^.])$
\ /
\ /
\/
`-- This is the key, match any non-period character at the end.
Demo: http://rubular.com/r/JZb3RehqrR
As anubhava pointed out in the comment, the above regex does not capture empty comment lines. If you wish to also capture the empty comment lines, you can add a ?
to make the comment optional:
^\/\/(.*[^.])?$
^
|
`-- Added this in order to make the comment optional
Demo: http://rubular.com/r/INyArTf9qQ
Upvotes: 4