I have a Problem to understand regex! Every time I think I do it - I don’t do it!
The Problem:
I write a formatter for a custom language (aveva Intouch). Now I try to find all keywords to uppercase them.
The expression is:
/(\b(as|eof|if|endif|then|dim)\b)/gmi
it's ok... - now please not in comments ({ comment }
):
/(?![^{]*})(\b(as|eof|if|endif|then|dim)\b)/gmi
it works... now please not in strings to:
There I find a solution to select text between quotes:
But I CAN'T reverse it
/(?!((["'])(?:(?=(\\?))\2.)*?\1))(\b(as|eof|if|endif|then|dim)\b)/gmi
I try it now for hours, and look for some issues it will not work. I think there is a small but general understanding problem.
Question:
How I can create a regex including both: select all keywords from text where the text is not in comment AND not in string?
Please help me understand the combination of select / negation of them, and combination of them. Or is it not the best practice to use regex for this problem?