How I can extract {{template|{{template2}}|other params}} from this string if we just know “template”:
{{template0}}
{{template|{{template2}}|other params}}
{{template3}}
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.
This should do what you want:
It uses a word boundary (
\b) after ‘template’ so it will not match ‘template0’ or ‘template3’. There.Moption is used so^and$will match the beginnings and ends of lines, instead of the beginning and end of the string.Edit: Try the following regex for the newline case from your comment:
This should work whether you put the newline before or after the
|.Edit 2: It is very important with regex questions that you specify what the input can look like up front. Here is another version that works with the text from your latest comment:
Now it will handle multiple newlines correctly, and I added the
}}at the end in case your match is the last bracketed group before lines with other formats.