re.search slashes

pyluke user at example.net
Sat Feb 4 14:29:23 EST 2006


pyluke wrote:
> I'm parsing LaTeX document and want to find lines with equations blocked 
> by "\[" and "\]", but not other instances of "\[" like "a & b & c \\[5pt]"
> 
> so, in short, I was to match "\[" but not "\\]"
> 
> to add to this, I also don't want lines that start with comments.
> 
> 
> I've tried:
> check_eq = re.compile('(?!\%\s*)\\\\\[')
> check_eq.search(line)
> 
> this works in finding the "\[" but also the "\\["
> 
> so I would think this would work
> check_eq = re.compile('(?![\%\s*\\\\])\\\\\[')
> check_eq.search(line)
> 
> but it doesn't.  Any tips?

Alright, this seems to work:

re.compile('(?<![(\%\s*)(\\\\)])\\\\\[')



More information about the Python-list mailing list