How would I formulate a search pattern for matching if
statements that don't have an opening curly brace on the next line? I assume it requires the use of something like [^{]
or \@!
, but I'm having trouble getting things to work correctly.
I'd like to match:
if(some_condition)
return;
but not:
if(some_condition)
{
return;
}
The if
and {
may be indented one or more levels and I think trying to account for the indentation is what's causing my problems.
My first attempt was to use this pattern:
if(.*\n\s*[^{]
This works if things aren't indented, but once they are it matches any if
statement regardless of whether the first non-white space character on the next line is a {
.
{
will be matched by the[^{]
, while the\s*
eats one whitespace less. To avoid this, include the whitespace (and TAB, if needed) in that exclusion list:[^ {]