I am trying to build a (multiline) pattern for a linter, to catch cases where:
- There is a
Text(
declaration - That is not followed by
.appFont(
declaration... - ...before the next occurrence of
}
(end of function) orText(
(another Text declaration...)
After many hours on regex101 (and consulting gpt...) I got these 2:
Text\([\s\S]*?\)[\s\S]*?(?!\.appFont)
This just catches the part that's before the .appFont
, but I want the entire catch to fail if .appFont
is found...
Text\([\s\S]*?\)[\s]*?(?!appFont)[\s\S]\}
This just catches everything, ignoring appFont
being in the sting entirely...
In the following example, only the 2nd case should be captured:
Text("blah")
.appFont(.body)
}
Text("blah")
}
Text(
"blah"
)
.appFont(.blah)
}
I tried to read about negative lookahead but I think I still somehow just use it wrong, or somehow cause it to be ignored when I add [\s\S]
maybe?