python - 匹配以相同未知字符开头和结尾的多行字符串
问题描述
正则表达式匹配以 'banner ......' 开头的多行字符串,其中 x 是从正则表达式本身提取的
r'banner (\^|\$)(.*\n)*(\^|\$)'
将有助于 'banner ^ ........ ^' 或 'banner $ .. $' 但如果我不知道这个角色是什么并且希望它成为之后的角色怎么办'横幅'
我有一个解决方法,我捕获这个未知字符,然后在第二个正则表达式中使用它,但是有没有可能或更好的方法来做到这一点。
示例文本
banner ^
------ WARNING ---------------------------------------------------------
This equipment is the property of XYZ.
Any unauthorised connection attempt is prohibited and will result
in criminal prosecution under applicable criminal laws.
--------------------------------------------------------------------------
^
或者
banner $
_____________________________
| Unauthorized access to this |
| system is forbidden and |
| subject to prosecution. |
| All actions performed on |
| this device are logged. |
-----------------------------
. .
\`-"'"-'/
} 6 6 {
=. Y ,=
/^^^\ .
/ \ )
( )-( )/
"" ""
$
但请记住字符 $ / ^ 是未知的干杯
解决方案
推荐阅读
- javascript - 未找到 webpack es6 模块
- machine-learning - 无法克隆对象 keras.wrappers
- python - python数据帧时间序列划分成更小的时间窗口循环
- javascript - 在材质ui选择中添加文本框
- python - Pytorch 在 Conv2D 中的默认填充是什么意思?
- javascript - 如何使用 mapbox-gl-directions 设置起点和终点?
- java - 在哪里设置 BluetoothGatt 连接优先级
- mysql - 获取自定义 MYSQL 查询结果
- jquery - 如何使用 jquery ajax 删除 html 选择文件选项
- github - 为什么 Dependabot 尝试向 JCenter 进行身份验证?