What I want to do is the following:
I will get two types of lines in my string.
line 1: "}else{"
- this is the one I want to match that has the else keyword and that allows one or two braces either forward or backward
Line 2: "}else if(cond){"
- I don't want this to match
with the current code the two match.
regex code:
\b(else)\b
It should match like this
caso 1 : }else{
caso 2 : else{
caso 3 : else
caso 4 : else
A regular expression that works for your case is
That allows any number of spaces from the beginning of the line (
^
), followed by an optional curly brace and any other number of spaces, the wordelse
, again spaces and another optional curly brace, more spaces, and the end of the line ($
).Demo --> https://regex101.com/r/DKmiU0/1