简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM