python - 避免将正则表达式与行首匹配
问题描述
我想出了以下正则表达式:
(.*\\\\documentclass.*)|(.*\\\\documentstyle.*)
此正则表达式将用于确定文档是否包含 \documentclass 或 \documentstyle 标记。
我想避免匹配以%
这样开头的字符串:
% To use with LaTeX, use \documentstyle[psfig,...]{...}
我怎样才能包含某种负面的lookbehind以避免匹配这个字符串?
解决方案
使用(使用多行模式)锚定到行^
首,负前瞻%
,然后交替:
(?m)^(?!%)(?:.*\\document(?:class|style).*)
推荐阅读
- ibm-mq - 可以在两个远程 qmgrs 中使用具有相同 CN 的证书吗?
- vue.js - 图例未显示使用 Echarts 的 vue.js 项目
- javascript - 使用 ShellExecute 正确识别打开的 Web 浏览器以使用 document.getElement
- archunit - 确保从另一个方法调用?
- sql-server - SQL Server 2019 忽略 WHERE 子句?
- acumatica - 可以为 AP 账单分配不同的审批人
- laravel - 使用 Laravel Controller 加载索引时获取当天的记录
- python - 将所有可能的组合应用到代码中以计算分数
- javascript - 如何修复 webpack-pwa-manifest 漏洞?
- mysql - 如何将 JSON 对象中返回的 mySQL 日期时间转换为 Swift 日期?