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 9231115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:59:27+00:00 2026-06-18T05:59:27+00:00

update 0 I added the code with for (… match in) below. update 0

  • 0

update 0

I added the code with for (... match in) below.

update 0

My source text repeats approximately every 40 lines. Below I show 8 lines for each of 2 repetitions below. The full data set is here. I need from the “[Board]” line the one or two digits between the quotes; from the “[Dealer]” line I need the single letter between the quotes.

[Board "1"]
[Dealer "N"]
[Vulnerable "None"]
[Deal "N:Q952.652.KJT4.95 T.KQT84.A865.J73 K8763.A7.Q.KQT84 AJ4.J93.9732.A62"]
[Scoring ""]
[Declarer ""]
[Contract ""]

[Board "2"]
[Dealer "E"]
[Vulnerable "NS"]
[Deal "E:K8542.3.4.AT7532 J76.K7.AT85.KQJ8 QT3.AJ84.KJ963.4 A9.QT9652.Q72.96"]
[Scoring ""]
[Declarer ""]
[Contract ""]

The following regex sort of works, but only picks up one match, not the 30+ matches in my text.

NSString *toMatch = @"\\[Board \"([0-9][0-9]?)\"\\].*\\[Dealer \"([NEWS])\"\\]";
NSRegularExpression *regex = [NSRegularExpression  regularExpressionWithPattern:toMatch options:NSRegularExpressionDotMatchesLineSeparators error:&error];
for (NSTextCheckingResult* match in [regex matchesInString:string options:NSRegularExpressionDotMatchesLineSeparators range:NSMakeRange(0, [string length])])
    {
        NSLog(@"Number of ranges in match: %u", match.numberOfRanges);
        for (NSUInteger i = 0; i < match.numberOfRanges; ++i)
        {
            NSRange matchedRange = [match rangeAtIndex: i];
            NSString* tstring = [string substringWithRange: matchedRange];
            NSLog(@"range %lu string: %@", (unsigned long)i, tstring);
        }
    }

I suspect the problem is in the linefeeds, but I don’t know how to fix it and the options
. This is a continuation of this question.

How do I fix the regex pattern to get the multiple matches?

(In addition, I need the following on the “[Deal]” line, but let’s ignore that for now. I need four separate groups, the first after the “:” and before the space, the second and third are between spaces, and the last is everything after the last space and before the quote.)

  • 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-18T05:59:29+00:00Added an answer on June 18, 2026 at 5:59 am

    I could be wrong, but I think the problem in your pattern is that you have .* and you have chosen NSRegularExpressionDotMatchesLineSeparators, so that .* will match everything until it reaches the last occurrence of [Dealer in the source text.

    You can turn the .* into a “non-greedy” version by using .*?, alternatively you could avoid having the .* at all and replace it \\n (assuming your input is delimited with a single \n). Note that in order for the regular expression compiler to see \ and n (which is the recognised escape sequence to match a linefeed character), you have to escape the \ in the NSString, so you have to use \\n, i.e.:

    NSString *toMatch = "\\[Board \"([0-9][0-9]?)\"\\]\\n\\[Dealer \"([NEWS])\"\\]";
    

    If your source text has Windows line endings you could use \\r\\n instead, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: I added my new solution at the UPDATE answer below. I try to
UPDATE 1 ADDED UPDATED CODE I have a django template on app engine. Currently
UPDATE: Added the textEquals selector code. I am using jquery and autocomplete for a
In my CMS I've added this code <div><?php include(my_contact_form.php) ?></div> which updates to a
I updated my code with string dates created with new Date and added back
Update : Added simple test example http://jsfiddle.net/7UhrW/1/ using normalize.css. Chrome/WebKit and Firefox have different
update I added a metabox using http://codex.wordpress.org/Function_Reference/add_meta_box Unfortunatly it only adds the metabox to
Update: I've added an answer that describes my final solution (hint: the single Expr
I added a counter cache but can't get it to update. But I can
There're files/folders that were deleted and then re-added to the repository. svn update >

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.