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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:47:57+00:00 2026-05-30T23:47:57+00:00

I have an array of data from which I would like to extract rows

  • 0

I have an array of data from which I would like to extract rows containing numbers and numbers only. Examples on rows:

15, +2, ‘ ‘, 7, 9, +21

(The ‘ ‘ represents one or more whitespaces).

In this case I would like to extract only 15, 7 and 9. I use a predicate in the following way:

NSString *pattern = @"[^0-9]";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
if (![predicate evaluateWithObject:myStringToMatch])
// Extract ...

I have tested my pattern using an online regex tester and found that [^0-9] does match anything but the numbers 0-9. However when I run the above code it only matches the whitespaces and not the eg +2, which I am pretty sure that it should do. Just to clarify, myStringToMatch is an NSString object.

I have no clue why it doesn’t match my pattern. Can anyone give me a hint on what I’m doing wrong?

Thanks.

  • 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-05-30T23:47:59+00:00Added an answer on May 30, 2026 at 11:47 pm

    You regex matches anything but a single digit. If you are going to match rows containing numbers and numbers only, you need a regex which will not match on rows containing non-numbers.

    You can use the following regex: ^[0-9]+$. It matches one ore more (+) digits ([0-9]) in a row and nothing else (anchors ^ and $ ensure that).

    Then, instead of filtering rows that don’t match, you process only the rows that do:

    if ([predicate evaluateWithObject:myStringToMatch])
    // note the absence of negation operator
    // Extract ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 1d array containing Nd data, I would like to effectively traverse
I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
I have a byte array which I would like to access by Int32 pointer
I have an application with a ListView ('SysListView32') control, from which I would like
I have a model that I'm trying to retrieve an array of data from,
I have taken the data from database into array now I want it to
Let say I have an array like: Array ( [0] => Array ( [Data]
I have an array of a few million numbers. double* const data = new
I have a php page which displays class schedule data for each user from
I am trying to retrieve particular data from a txt file and would like

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.