I am referring a regular expression cheat sheet.
It says
{3,5} means 3,4,and 5
{3,5}? means 3,4,5 ungreedy +
what does ungreedy +indicate?
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.
The quanitifier
{3,5}?means that it will try to match 3 occurrences first, then see if the rest of the expression matches. If the rest of the expression fails it will backtrack and try 4, then finally 5.The greedy version
{3,5}will try the matches in the opposite order – longest first.Note that greediness does not affect whether or not a string matches. It only affects the order in which the engine performs the search, and the contents of the captures if there are capturing groups.
Here’s an example that demonstrates the difference. Imagine you have the string
aaaaabc.(a{3,5})(\w*)will captureaaaaaandbc. (rubular)(a{3,5}?)(\w*)will captureaaaandaabc. (rubular)