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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:36:17+00:00 2026-06-17T22:36:17+00:00

i try to extract simple string from string with out success it looks simple

  • 0

i try to extract simple string from string with out success it looks simple but the result alwways as
the string
here is what i have :

-(NSString*) ExtractArtistNameFromString:(NSString*) line
{

    NSString* substringForMatch = @""   
    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\d+\\s+(.*)"
                                                                        options:NSRegularExpressionCaseInsensitive
                                                                        error:&error];

    if (error) {
        NSLog(@"Error:%@", error);  
    }

    NSArray *matches = [regex matchesInString:line
                                              options:0
                                              range:NSMakeRange(0, [line length])]; 

    NSUInteger elements = [matches count];
    NSLog(@"numberOfMatches:%u",elements);

    if(elements > 0)
    {

        for(NSTextCheckingResult *match in matches)
        {
            NSString* substringForMatch = [line substringWithRange:match.range];
            NSUInteger slen = [substringForMatch length];
            NSLog(@"Extracted  : %@",substringForMatch);
            NSLog(@"%u",slen);
            NSLog(@"%@",substringForMatch);
        }        
    }
    return substringForMatch;
} 

input string is :

1 Barsotti, Marcel

what im trying to extract is the name that is : Barsotti, Marcel

and when i run the app i get this result :

2013-01-29 11:31:24.056 file_parser[2496] numberOfMatches:1
2013-01-29 11:31:24.062 file_parser[2496] Extracted  : 1        Barsotti, Marcel
2013-01-29 11:31:24.064 file_parser[2496] 18
2013-01-29 11:31:24.066 file_parser[2496] 1     Barsotti, Marcel

im using GNUsetup in windows , the make command is:

make CC=clang

  • 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-17T22:36:18+00:00Added an answer on June 17, 2026 at 10:36 pm

    I see what you’re trying to do. The documentation for NSTextCheckingResult shows that a result can have multiple ranges within it, yet you’re only referencing the first range.

    For example, your RegEx and your string will have 1 match, with 1 capture group within it. These are:

    1. 1 Barsotti, Marcel
    2. Barsotti, Marcel

    Whilst you only have one NSTextCheckingResult, there are multiple ranges within it. You were using

    NSString* substringForMatch = [line substringWithRange:match.range];
    

    This will return the first result listed above. What you want is the second. In order to get this, you need to use

    NSString* substringForMatch = [line substringWithRange:[match rangeAtIndex:1]];
    

    To make sure you don’t exceed the rangeAtIndex:, the property numberOfRanges exists to allow you to keep within bounds. Remember, [match rangeAtIndex:0] is the same at match.range.

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

Sidebar

Related Questions

I try to extract the media description of a SDP package. I have a
I have a KML file and I extract the last coordinates and try to
Long story coming up, but I'll try to keep it brief. I have many
I have a simple web service operation like this one: [WebMethod] public string HelloWorld()
I try to extract coefficient from equations (system of equations) into list (matrix). I
I want to extract a username from a string that user has typed into
I am trying to parse html using BeautifulSoup to try and extract the webpage
I try to download a zip file to android and then extract the zip
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]

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.