I am trying the following:
.+\?[^\?].+\?
That is, match everything til a “?”, then, if no other “?” after that, match everything til another “?”. I guess it is not working because the first .+ matches the entire string already.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your description isn’t precise, but here’s the rules I assume you need your regex to satisfy:
This is actually pretty simple.
Note that this will match a substring of a larger string. If you need to ensure the entire string exactly matches this, throw in
^and$anchors:Explanation:
^Start of the string. In a multiline context this also matches start of the line, but you’re probably not in a multiline context.
[^?]Match anything that’s not the literal character ‘
?‘.*Match zero or more of the previous token.
\?Match a literal ‘
?‘.[^?]Match anything that’s not the literal character ‘
?‘.+Match one or more of the previous token. This ensures that you cannot have two ‘
?‘ in a row.\?Match a literal ‘
?‘.$Match the end of the string (or the end of the line in a multiline context).
Note: I assumed zero or more non-‘
?‘ before the first ‘?‘. This will match something like?abc?. If this is illegal, change the first*to a+.