UPD: I need to check if @if(Medellin) so take "City Medellin" but if @if(null) don’t take anything
Here is my pattern:
(?<!@if\(null\)).*?@end$
Testing strings:
@if(Medellin) City Medellin @end
@if(null) City Medellin @end
I understood that first checks right side, and it takes all string 🙁
>Solution :
You can use
@if\((?!null\))\w+\)\s*(.*?)\s*@end\b
See the regex demo. To match across lines, you will need either (?s)@if\((?!null\))\w+\)\s*(.*?)\s*@end\b or @if\((?!null\))\w+\)\s*([\w\W]*?)\s*@end\b.
Details:
@if\(– a@if(string(?!null\))– a negative lookahead that fails the match if there isnull)string immediately to the right of the current location\w+– one or more word chars\)– a)char\s*– zero or more whitespaces(.*?)– zero or more chars as few as possible\s*– zero or more whitespaces@end\b–@endwhole word.