regex 如何告诉egrep不接受哪些字符

o8x7eapl  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(93)

我想接受以s开头的字符串,而不是下一个字符(无论它是什么)必须在脚本中包含两次以上(但不能更少,也不能更多),并且在此字符之前不能是反斜杠。所以:

s(.)[now some chars except (.) and not ending with \]\1[some chars but not (.) and not ending with \]\1[some chars but not (.)]

\1和(.)和s是正则表达式的真实的部分

yqhsw0fo

yqhsw0fo1#

我不认为白鹭会成功。
你需要一个可以做lookaheadAssert的grep,原因如下:
/^ s (.) (?:(?:\\.|(?!\1).)+\1){2} (?:\\.|(?!\1).)+ $/xs

/^             # Begin of string
     s
     (.)                # capture first char after 's'
     (?:                # Begin Grp
         (?: \\.          # begin grp, escaped anything
           | (?!\1).        # OR, any char that is not (.)
         )+               # end grp, do this more than once
         \1               # Followed by (.)
     ){2}               # End Grp, do this exactly twice

     (?: \\.            # begin grp, escaped anything
       | (?!\1).           # OR, anchar that is not (.)
     )+                 # end grp, do this more than once

 $/xs         # End of string, x and s modifiers

相关问题