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

Regex 如何告诉egrep不接受哪些字符,regex,grep,Regex,Grep,我想接受以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是正则表达式的真实部分我认为egrep不会削减它。 您需要一个能够进行前瞻性断

我想接受以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是正则表达式的真实部分

我认为egrep不会削减它。
您需要一个能够进行前瞻性断言的grep,原因如下:

/^s(.)(?:(?:\\.\124;(?!\ 1)。+\1){2}(:\\.\124;(?!\ 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

很难理解你的例子。您可以通过在metatext周围添加例如[](“[现在除了…]之外还有一些字符”)来澄清它,以便更容易理解什么是字符串的一部分,什么是解释的一部分。