I need for Java a check of the last line. I have a String which will be processed further by TeX compiler. There the very first % in a line is treated as comment and all the rest of the line is 'not seen' by the compiler.
But the very first % is little bit tricky because it could be escaped by an \ so a \% should be ignored.
So basically I want to check if the very last line ends with a comment or not?
e.g.
(a) last line % now with comment
(b) last line with escaped \% and not treated
(c) last line withouth any special chars
(d) last line terminates with %
(e) last line terminates with escaped \%
(f) beginning % but even escaped \% is ignored
For a check I need to have positive: a, d and f while the others should be ignored.
As requested my approach up till now:
[^\n]*$
tests the very last line. Fine but now I don't even know how to match in the very last line just a %. I would have exepected that a (%)? would match only if % is available but with even (c) is positive since it matches the last line.
Could anybody help how to filter only the % I'm looking for?