0

While trying to answer a SE question, I generated the following regex. Can anyone help me regarding generating a string that would comply with this regex?

^(.*)((?=(first ending\.))|(?=(second ending\.)))$

I need to match this:

contents.  first ending.
contents.  second ending.
contents.  first ending.  second ending.
contents.  second ending.  first ending.
hacker315
  • 1,704
  • 1
  • 11
  • 18
  • The regex reads: "match the beginning of a line (`^`), followed by zero or more characters other than a newline (`.*`), saved in capture group 1 (`(.*)`), followed by `(?=...)` (a *positive lookahead*) `"first string."`, which is saved to capture group 2 (`((?=(first ending\.))`, or (instead of all of the foregoing) the current location must be followed by `"second ending\."`, saved to capture group 3, followed by the end of the line (`$`). The expression contains an extra `)` at the end. Either it should not be there or there is a missing `(` or `(?:` or the beginning of a lookaround. – Cary Swoveland May 25 '20 at 21:49
  • @CarySwoveland The curly braces are fine.. This regex didn't match any of these strings.. That's the problem.. – hacker315 May 26 '20 at 10:38
  • I see I answered a question you did not ask. I can’t say what I was thinking. The question is confusing, however, as you are asking for a string that the regex would match but then list strings you would like it to match, suggesting you want the regex corrected. In any event, the regex must first be fixed to deal with the problem of unbalanced parentheses that I mentioned. If you do so I will see if I can help. – Cary Swoveland May 26 '20 at 12:47
  • thanks Cary for prompt response,, I am looking for a string that would match the above regex.. – hacker315 May 26 '20 at 14:55

0 Answers0