How do I tell RegEx (.NET version) to get the smallest valid match instead of the largest?
Share
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.
For a regular expression like
.*or.+, append a question mark (.*?or.+?) to match as few characters as possible. To optionally match a section(?:blah)?but without matching unless absolutely necessary, use something like(?:blah){0,1}?. For a repeating match (either using{n,}or{n,m}syntax) append a question mark to try to match as few as possible (e.g.{3,}?or{5,7}?).The documentation on regular expression quantifiers may also be helpful.