Reputation: 85
Is it possible in RegEx; and if so how, to search from character to character only if specified characters are not included between them.
For instance:
Function
{
Parameter Parameter_Name
}
Function
{
}
I want to run a search starting with "Function" and ending with "}" where "Parameter" does not appear between the two.
For reference, I am using Notepad++'s RegEx search, and I have ".matches newline" enabled, and have no trouble performing other multiline searches, I'm just not sure of the syntax.
I tried something along the lines of
Function.*!?Parameter.*?\}
But this search just caught everything between Function and the last "{" in the file. Meanwhile the below will always stop at the first "}" character.
Function.*?\}
What am I missing?
Upvotes: 0
Views: 59
Reputation: 124225
Naive answer but hire it goes
Function(?![^}]*\bParameter\b)[^}]*?\}
I assume that:
Function
can't contain nested {...}
blocks (at least no nested }
)Parameter
is separate word, so Parameter_Name
will not be counted as Parameter
.(?!...)
part is negative-look-ahead.
Function(?![^}]*\bParameter\b)
checks if after Function
there is no Parameter
which has no }
before it. In other words it can have any other character beside }
before which means that this Parameter
will not be outside of currently checked Function{...}
range. This means that negative-look-ahead will check only until it will find first }
or end of your text.
Upvotes: 1