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

The Archive Base Latest Questions

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

For one NSString, I have N pattern strings. I’d like to extract substrings around

  • 0

For one NSString, I have N pattern strings. I’d like to extract substrings “around” the pattern matches.

So, if i have “the quick brown fox jumped over the lazy dog” and my patterns are “brown” and “lazy” i would like to get “quick brown fox” and “the lazy dog.” However, the substrings don’t necessarily need to be delimited by whitespace.

Another example would be if you had multiple paragraphs of text and wanted to find all instances of “red” and “blue” in the text, but you wanted to show the instances of “red” and “blue” in context, but by “context” you didn’t care if the context started and ended with the beginnings or endings of words in the body of text, so if you had one of the sentences in the body of text as “there are a whole lot of red ducks in the trees” the result could be “whole lot of red ducks in” or “ole lot of red ducks in th” and it wouldn’t matter — i’m not looking for a whitespace based solution. it could just be to find “red” and get the substring that is “red” and the 10 characters before and the 10 characters after.

In other words, there are some “range” based string matching functions. I was hoping there was an easy way to match multiple strings at once and return each string’s matching point plus surrounding characters.

  • 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-13T23:16:57+00:00Added an answer on May 13, 2026 at 11:16 pm

    You could use regular expressions provided by a third party framework (e.g. RegexKit or RegexKitLite). To create the RE, join the patterns with “|” and prepend and append parentheses and patterns to capture context. Match the string against the regexp.

    Some example prefix & suffix patterns:

    • ".{,15}(", ").{,15}" to match up to 15 characters
    • "(\w+\W+){,4}(", ")(\W+\w+){,4}" to match up to 4 words
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 447k
  • Answers 447k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The only time you would want to use the recovery… May 15, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer Thanks for clarifying your question. Most Exceptions in Python don't… May 15, 2026 at 7:30 pm
  • Editorial Team
    Editorial Team added an answer So I have my Activity, and on pressing a "Quit"… May 15, 2026 at 7:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.