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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:38:52+00:00 2026-06-03T14:38:52+00:00

I have a problem with reading the image path of a string like ->

  • 0

I have a problem with reading the image path of a string like -> background-image:url(/assets/test.jpg)

I wanna have the string inside of the brackets without the brackets self.

Here is my code used:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\bbackground-image:url\(.*\)\\b" options:NSRegularExpressionCaseInsensitive error:nil];

        thumbnail = [regex stringByReplacingMatchesInString:thumbnail options:0 range:NSMakeRange(0, [thumbnail length]) withTemplate:@"$1"];

what i get is (/assets/test.jpg)

  • 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-03T14:38:53+00:00Added an answer on June 3, 2026 at 2:38 pm

    Use the following pattern to get the expeced result:

    background-image:url\\((.*)\\)
    

    Applied to your code:

    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"background-image:url\\((.*)\\)" options:NSRegularExpressionCaseInsensitive error:nil];
    

    Using this the result will be “/assets/test.jpg”, just as you want it to be.

    Your code should have given you a warning about an unknown escape sequence for “\(“. You have to use “\\(” to escape a “(“. Also get rid of “\\b” at the beginning and end of your pattern.

    But be aware that this pattern only works when your string only contains “background-image:url(somevaluehere)”

    EDIT:

    What does \\b mean?

    \\b is a word boundary, usually expressed as \b. In an NSString you need to write \\b because you need to escape the \ so it will be treated as real backslash.

    Here some information on what word boundaries match:

    There are three different positions that qualify as word boundaries:

    • Before the first character in the string, if the first character is a
      word character.
    • After the last character in the string, if the last character is a word character.
    • Between two characters in the string, where one is a word character and the other is not a word character.

    Simply put: \b allows you to perform a “whole words only” search using
    a regular expression in the form of \bword\b. A “word character” is a
    character that can be used to form words. All characters that are not
    “word characters” are “non-word characters”.

    Taken from http://www.regular-expressions.info/wordboundaries.html

    I hope this clarifies this a bit.

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

Sidebar

Related Questions

I have a problem reading a txt file to insert in the mysql db
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
I have a problem with reading some gml files in c#. My files do
I have some problem with reading from sqlite3 database. -(void) readMessengesFromDatabase { sqlite3 *database;
i have one problem controlling checkbox, i'm reading, and searching about the topic but
i have been reading about multiple inheritance What is the exact problem with multiple
My problem involves checking if I have a valid database connection before reading from
I have problem running and debugging this piece of code: bool readSectionHeaders(char* path, int
basically i am reading image bytes from file i have a loop which has
I have problem creating new instance of excel 2007 using VBA (from Access 2002).

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.