-1

I want to accept string that begins with s than the next character (whatever it is) must be conatined in script two more times (but not less, not more) and before this char cannot be a backslash. So:

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

\1 and (.) and s are real part of regex

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 2
    It's hard to understand your example. Can you clarify it, maybe by adding for example [] around metatext ("[now some chars except...]") so that it's easier to understand what is part of string and what is part of explanation. – Olli Mar 27 '11 at 13:42

1 Answers1

0

I don't think egrep is going to cut it.
You need a grep that can do lookahead assertions, here's why:

/^ 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