gpt4 book ai didi

javascript - 使用正则表达式查找我选择的前两个相同字符之间的文本

转载 作者:行者123 更新时间:2023-12-04 13:18:35 24 4
gpt4 key购买 nike

Assume the following output



.
20198818-119903 | firmware-check | passed: host test-1000 is connected to a test with Version: 333 | |
20198818-119903 | other-test-123 | passed: host test-1000 is connected to a test with 333:
20198818-119903 | test4| passed :| host | is connected to a test with 333
20198818-119903 | something | passed: host test-1000 is connected to a test with Version:

I want to extract firmware-check, other-test-123, test4, and something



所以基本上 一切之间 前两个竖条。

我试图用 txt2re 解决这个问题,但没有按照我想要的方式工作(例如不忽略第三行的主机)。我从未使用过正则表达式,也不想仅针对这种特殊情况学习它。有人能帮助我吗?

最佳答案

你可以用这个

^[^|]+\|([^|]+)

enter image description here

let str = `20198818-119903 | firmware-check | passed: host test-1000 is connected to a test with Version: 333 | |
20198818-119903 | other-test-123 | passed: host test-1000 is connected to a test with 333:
20198818-119903 | test4| passed :| host | is connected to a test with 333
20198818-119903 | something | passed: host test-1000 is connected to a test with Version:`

let op = str.match(/^[^|]+\|([^|]+)/gm).map(m=> m.split('|')[1].trim())

console.log(op)

关于javascript - 使用正则表达式查找我选择的前两个相同字符之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57098627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com