惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
A
Arctic Wolf
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
A
About on SuperTechFans
P
Palo Alto Networks Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog
P
Proofpoint News Feed
D
DataBreaches.Net
Cyberwarzone
Cyberwarzone
T
Tor Project blog
IT之家
IT之家
P
Proofpoint News Feed
Help Net Security
Help Net Security
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
Microsoft Azure Blog
Microsoft Azure Blog
V2EX - 技术
V2EX - 技术
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
B
Blog
N
News and Events Feed by Topic
The Cloudflare Blog
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
T
The Blog of Author Tim Ferriss
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
Hacker News - Newest:
Hacker News - Newest: "LLM"
L
LangChain Blog
I
InfoQ
F
Full Disclosure
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
H
Hacker News: Front Page
V
V2EX

正则表达式

增加一点动力学正则 - V2EX 求教,如何系统性的学习正则表达式? - V2EX sigil 正则表达式疑问 - V2EX editplus 中如何去掉空格 - V2EX 临门一脚,这个正则怎么匹配不上字符串啊? - V2EX 正则表达式合集帖(希望本帖能存活十年以上) - V2EX 正则如何完整匹配整个单词 - V2EX 请问 EM 正则如何在文章最前面添加一段话 - V2EX 求教,这个正则怎么写 - V2EX /(\w*)*$/.test('aaa#')这个正则导致我们的页面炸了……不同语言居然不一样 - V2EX 这个可以用正则表达式做到吗?GPT 聊了半天了 - V2EX [求助]如何利用正则表达式将文本或换行用 p 标签包裹起来 - V2EX 正则表达式 locate --regex 'bin/(bz|gz|zip)'有没语法问题? - V2EX 上下两行内容合并正则有办法能实现吗 - V2EX 正则表达式如何截取一个完整括号的内容 - V2EX 有对 posix-正则 有研究的吗?问下 - V2EX editplus 求个全选正则忽略前面的符号及符号内的内容 - V2EX 各位老哥,正则怎么写能排除一个或多个特定的 IP,匹配剩余所有 IP(或者说是否可以实现) - V2EX 想请教一个正则表达式,这正则能做吗 - V2EX 使用正则.*ab.*搜索二进制文件(pdf 格式),搜不到 ab 但是.*a.*可以找到 a,除了 ab 还有别的正则写法么? - V2EX 这个正则表达式怎么写,要么在开头,要么前面有空格 - V2EX 求助:正则获取 sql 语句中的表名 - V2EX Safari 上不支持向后匹配的正则表达式,请教替代方法 - V2EX 正则表达式如何忽略子字符串中的内容 - V2EX 求助 nginx 的 rewrite,需求是把 http 流量转到 https - V2EX 求大佬指点 - V2EX iHateRegex 一个收录各种正则表达式的网站 - V2EX 请教一下,如何利用正则表达将 html 中在<p></p>之间的/筛选出来 - V2EX ep 求一个数字和单位的正则 - V2EX 正则菜鸟求教 - V2EX 正则 backtrack 请教 - V2EX 求给生成一个正则表达式,年龄大了,脑子不够用了 - V2EX 请问正则这种替换该怎么填 - V2EX 求个表格补 0 的正则表达式。 - V2EX 求个正则? pathname/{id}/sub_pathname - V2EX [求助] 请问正则从后往前非贪婪匹配 - V2EX [求助]正则表达式的正向否定预查,无法筛选某些字符串 - V2EX 全书很多空格,求一个正则表达式帮我看看是否行的通? - V2EX 请问正则表达式中,中间部分的?:的作用是什么? - V2EX 关于正则数字添加千分号 /\B((?=(?:\d{3}))+$)/g 不太理解 - V2EX 请问提取 caseId 的数字正则怎么写? - V2EX 求个正则 - V2EX JS 里面的 string.match,怎么把匹配字符串取出来? - V2EX 求大佬指点 js 正则,拜谢 - V2EX 求问:正则对位置匹配是怎么处理的? 正则表达式如何嵌套匹配 - V2EX 我请教一个 Python 正则表达式问题 - V2EX 提问一个正则匹配的问题 - V2EX
正则匹配,怎么匹配不定内容的成对的中间的内容呢? - V2EX
nyxsonsleep · 2023-10-27 · via 正则表达式

这是一个创建于 961 天前的主题,其中的信息可能已经有所发展或是发生改变。

彻底实现效果,请一杯咖啡(红包),聊表谢意。

...
abc.js: actual output: {
  "loc": {
    "start": {
      "line": 1,
    },
    "end": {
      "line": 1,
    }
  }
}
Error: xxxx

abc.js: actual error:
...

abc.js 不是固定内容(可能有 xxx.js 等),

abc.js 的数量不止一对,

actual output 和 actual error 是固定存在内容的有且仅有一对。

保留 abc.js 信息。

需要匹配多组

第 1 条附言  ·  2023 年 10 月 27 日

建议使用 python 作为示例,忘记说明了。不同语言的正则匹配库应该是略有区别的

Leon406

1

Leon406      2023 年 10 月 27 日

([^.\s]+\.js): actual output: (.*?)\1: actual error

分组匹配 group1 是 js, group2 是中间内容

nyxsonsleep

3

nyxsonsleep      2023 年 10 月 27 日

@Leon406

```
input_text="input_text.txt"
output_text="output_text.txt"
import re
def change():
with open(input_text) as f:
ss=f.readlines()
s=''.join(ss)
pattern = re.compile(r'([^.\s]+\.js): actual output: (.*?)\1: actual error')
rs=re.findall(pattern,s)
with open(output_text,'w') as fw:
for i in rs :
print(i[0])
fw.write(i[1])
# print(i[1])
print(len(rs))
change()
```

匹配结果 0 个。

Nile20

9

Nile20      2023 年 10 月 27 日

import re

PATTERN = re.compile(r'^(\w+\.js): actual (?:output|error): \{.*?^\}$', flags=re.MULTILINE | re.DOTALL)

txt = '''abc.js: actual output: {
"loc": {
"start": {
"line": 1,
},
"end": {
"line": 1,
}
}
}
Error: xxxx

abd.js: actual error: {
"loc": {
"start": {
"line": 1,
},
"end": {
"line": 1,
}
}
}'''

match_ls = PATTERN.findall(txt)

for m in match_ls:
print(m)

Nile20

10

Nile20      2023 年 10 月 27 日

python 强制用缩进来表示代码级别是我一直的槽点╮(╯▽╰)╭。这下全乱了