How can I get
Text t;
Graph g;
from
// Co
Text t;
Graph g;
// Co
?
// Co\r?\n(.*)\r?\n// Co
works when there is one line, but does not work with multiple lines.
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.
By default,
.matches any character except newlines (\n), but you can use thePattern.DOTALLflag to make it match newlines as well. So, for example, instead of this:you would use this:
Equivalently, you can set the
sflag inside the regex itself, using either of these styles:which lets you control exactly which part of the regex accepts a newline for
.. (But I’d stick with theDOTALLapproach unless you have a regex where.sometimes means the one thing, sometimes the other.)Edited to add: It seems very likely — but you’ll have to determine this for yourself, based on your use-case — that you need to use non-greedy quantification,
.*?, rather than greedy quantification,.*.