<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">On Friday, January 29, 2021 11:48:40 AM WET Kornel Benko wrote:</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Right, the last one should be escaped.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Given the line</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>          # \DeclareLaTeXClass[revtex,revtex.sty]{REVTeX (Obsolete Version)}</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> and the original regex</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">>        </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> '\\s*#\\s*\\\\DeclareLaTeXClass\\s*(\[([^,]*)(,.*)*\])*\\s*{(.*)}\\s*$' the</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> result in found(1) would be "revtex"</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> and found(2) would be the rest inside the escaped brackets, e.g.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> "revtex.sty"</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> Not escaping the last ']' probably not intended.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">> (I would escape also '{' and '}' if that were a perl regex)</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Now that you mention it the code should use raw strings in order to avoid doubling the backslashes, e.g. in order to match \DeclareLaTeXclass the code has "\\\\DeclareLaTeXclass" because the backslash needs to be escaped twice the first time for the regular expression and then each needs to be escaped again for python.</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">Using raw strings the results would be r"\\DeclareLaTeXclass" more in line with what we usually write. :-)</p>
<br /><p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">This is a detour that come from the code analysis and it does not come from Thibault's changes.</p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">-- </p>
<p style="margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;">José Abílio</p>
</body>
</html>