Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:46:30+00:00 2026-06-17T19:46:30+00:00

I am invoking the mentioned function and it is correctly iterating through all the

  • 0

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)?)*\]/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:46:32+00:00Added an answer on June 17, 2026 at 7:46 pm

    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 options value to enumerateMatchesInString. For example, it’s very easy to mistakenly invoke it like so:

    [regex enumerateMatchesInString:stringToSearch
                            options:NSRegularExpressionCaseInsensitive
                              range:NSMakeRange(0, [stringToSearch length])
                         usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
                             // This is called many times, 
                             // even when there is no match!
                         }];
    

    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 NSMatchingReportCompletion to the options, 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 NSRegularExpressionCaseInsensitive simply is not an appropriate value for the options parameter of enumerateMatchesInString … it’s an options value for regularExpressionWithPattern). Worse, NSRegularExpressionCaseInsensitive just happens to be identical to NSMatchingReportProgress, which generates the behavior you describe.

    The correct solution is to simply pass an options value of 0, like below, and enumerateMatchesInString will be called just for matches, and not for interim progress and not upon completion:

    [regex enumerateMatchesInString:stringToSearch
                            options:0
                              range:NSMakeRange(0, [stringToSearch length])
                         usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
                             // do stuff here
                         }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: When does invoking a member function on a null instance result in
compared to invoking a python library function that does the same thing. I've some
Not a Duplicate of Invoking virtual function and pure-virtual function from a constructor :
I m invoking a web service and they stop my service calls after an
I am invoking a web service function which is reading a users credentials from
I know this represents the object invoking the method and static methods are not
This is how I am invoking the click : $(#myDivId).click(function(e) { callAjax(); window.location =
After invoking git merge --no-commit <commit> , performing a commit will result in a
I have no issues invoking actions on UI controls through BeginInvoke and such, however,
I'm invoking a C++ function from within C#. This is the function header in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.