gpt4 book ai didi

regex - 抓取字符串直到一两个条件

转载 作者:行者123 更新时间:2023-12-04 08:51:40 25 4
gpt4 key购买 nike

假设我有以下两个字符串:

...some content above
Destination: Fox - Man (200.170.217.200)
...some content below
...some content above
Destination: Some content goes here and ends
...some content below
正则表达式应该捕获: Fox - ManSome content goes here and ends .
除了尾随括号之外,我想获取描述中的所有内容。基本上,它结合了这两个正则表达式:
Destination:\s*(.+\S)    # everything until the end of the line
Destination:\s*([^(]+\S) # everything until the first open parenthetical
我将如何组合这些,以便 exit at (优先?此处示例: https://regex101.com/r/5qUwRW/1

最佳答案

Destination:\s*([^(\n]+[^\s(])
proof
说明
--------------------------------------------------------------------------------
Destination: 'Destination:'
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[^(\n]+ any character except: '(', '\n'
(newline) (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
[^\s(] any character except: whitespace (\n,
\r, \t, \f, and " "), '('
--------------------------------------------------------------------------------
) end of \1

关于regex - 抓取字符串直到一两个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64070441/

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