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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:51:59+00:00 2026-05-15T10:51:59+00:00

Mac OS 10.6, Cocoa project, 10.4 compatibility required. (Please note: my knowledge of regex

  • 0

Mac OS 10.6, Cocoa project, 10.4 compatibility required.

(Please note: my knowledge of regex is quite slight)

I need to parse NSStrings, for matching cases where the string contains an embedded tag, where the tag format is:

[xxxx]

Where xxxx are random characters.

e.g. “The quick brown [foxy] fox likes sox”.

In the above case, I need to grab the string “foxy”. (Or nil if no tag is found.)

Each string will only have one tag, and the tag can appear anywhere within the string, or may not appear at all.

Could someone please help with a way to do that, preferably without having to include another library such as RegexKit. Thank you for any help.

  • 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-15T10:52:00+00:00Added an answer on May 15, 2026 at 10:52 am

    I’d suggest something like the following:

    NSString *subString = nil;
    NSRange range1 = [myString rangeOfString:@"["];
    NSRange range2 = [myString rangeOfString:@"]"];
    if ((range1.length == 1) && (range2.length == 1) && (range2.location > range1.location)) {
      NSRange range3;
      range3.location = range1.location+1;
      range3.length = (range2.location - range1.location)-1;
      subString = [myString substringWithRange:range3];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Cocoa Mac app where I need to display a window/view
I'm currently in a project that need to work both on Mac and Windows.
Xcode 3.25, Mac OS X 10.6, 10.5 compatibility required. I have a Mac Xcode
I have a very simple Mac Cocoa app that just has a Web View
In mac osx (cocoa), It is very easy to make a blank image of
I used the cocoa of MAC to develop a plugin with safari , I
I'm developing a Mac OS X Cocoa app and want to use several .dylib
I'm pretty new to cocoa for Mac development. I'm currently struggling with getting a
Assume I have a Cocoa-based Mac or iOS app. I'd like to run a
I'm confused by this: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/AccessorConventions.html#//apple_ref/doc/uid/20002174-178830-BAJEDEFB Supposing @interface Office : NSObject { NSMutableArray *employees; }

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.