brienna
brienna

Reputation: 1604

Avoid matching regex to beginning of line

I have come up with the following regex:

(.*\\\\documentclass.*)|(.*\\\\documentstyle.*)

This regex will be used to determine whether a document contains a \documentclass or a \documentstyle tag.

I would like to avoid matching a string starting with % such as this:

% To use with LaTeX, use \documentstyle[psfig,...]{...}

How may I include a negative lookbehind of some sort to avoid matching to this string?

Upvotes: 0

Views: 105

Answers (1)

CertainPerformance
CertainPerformance

Reputation: 370679

Anchor to the start of the line with ^ (with multiline mode), negative lookahead for %, and then alternate:

(?m)^(?!%)(?:.*\\document(?:class|style).*)

https://regex101.com/r/WjCkfb/1

Upvotes: 3

Related Questions