I am trying to write a regex to find comment lines in LaTeX. I created the following example. The last regex does not work. Can I have a single regex for all of the cases?
Before:
\usepackage{test}%COMMENT1
TEXT
%COMMENT2
TEXT
Value is 10\%, this should not be removed. %COMMENT3
begin{tikz}[
important 1,
%COMMENT4
important 2, %COMMENT5
]
TEXT
%COMMENT 6
TEXT
Table: value1&value2\\%COMMENT7
After:
\usepackage{test}
TEXT
TEXT
Value is 10\%, this should not be removed.
begin{tikz}[
important 1,
important 2,
]
TEXT
TEXT
Table: value1&value2\\
The is what I reached so far:
(^%(.*?)\r?\n)
Works for comment 2,4,6 when replaced with nothing
([\]{2}%(.*?)\r\n)
This works for comment 7 when replaced with \\\r\n
([^\]%(.*?)\r?\n)
This does NOT work for comment 1 because it select the '}'