I am invoking the mentioned function and it is correctly iterating through all the matches. Though, it does not finish executing after all the matched blocks were handled. What might I be doing wrong?
The used regexp is: /\[([^\[\{,]*(,\n)?)*\]/
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.
Judging from your answer to your own question, it appears that you solved the problem by passing
NSMatchingReportCompletion. I suspect that you may have cured a symptom rather than the disease.I wonder if you may have accidentally passed the wrong
optionsvalue toenumerateMatchesInString. For example, it’s very easy to mistakenly invoke it like so:This, at first blush, looks fine, the compiler doesn’t complain, but we get the undesirable behavior of the block getting called too many times, often with
result == nil.You can solve this problem by adding
NSMatchingReportCompletionto theoptions, and rather than getting the block called many times, it’s called just for the matches and once more upon completion. That fixes it, but it’s an inelegant solution and overlooks the source of the problem.The issue is that
NSRegularExpressionCaseInsensitivesimply is not an appropriate value for theoptionsparameter ofenumerateMatchesInString… it’s anoptionsvalue forregularExpressionWithPattern). Worse,NSRegularExpressionCaseInsensitivejust happens to be identical toNSMatchingReportProgress, which generates the behavior you describe.The correct solution is to simply pass an
optionsvalue of0, like below, andenumerateMatchesInStringwill be called just for matches, and not for interim progress and not upon completion: