gpt4 book ai didi

regex - 匹配正则表达式正则表达式草图引擎(不匹配子字符串)

转载 作者:行者123 更新时间:2023-12-04 07:52:00 25 4
gpt4 key购买 nike

我正在学习正则表达式,我正在尝试解决这个问题:https://regex.sketchengine.co.uk/cgi/ex1.cgi
到目前为止,我想出了:

^[psr][^ta|?!ea].*$
但是它不是检查它是否与作为子字符串的 'ea' 不匹配,而是尝试不匹配 'e' 和 'a' 作为第二个字符。我的错误是什么?

最佳答案

您的正则表达式错误,请参阅其说明:


节点
解释

^字符串的开头
[psr]任何字符:'p'、's'、'r'
[^ta|?!ea]任何字符除外:'t'、'a'、'
.*除\n 之外的任何字符(0 次或多次(匹配尽可能多的数量))
$在可选的\n 之前,以及字符串的结尾



.*p[ioa ]t.*
proof
说明
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
p 'p'
--------------------------------------------------------------------------------
[ioa ] any character of: 'i', 'o', 'a', ' '
--------------------------------------------------------------------------------
t 't'
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))

关于regex - 匹配正则表达式正则表达式草图引擎(不匹配子字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66915129/

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