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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:13:07+00:00 2026-06-17T04:13:07+00:00

Building an iOS app that needs to display some HTML string in a UIWebView

  • 0

Building an iOS app that needs to display some HTML string in a UIWebView object. I am trying to search, find for a pattern and replace with the proper link to an image. The image links are original something like [pic:brand:123], where pic is always pic , brand can be any alphanumeric, and the 123 is can also be any non-whitespace alphanumeric.

So far I have tried a few including:

NSString *pattern = @"\\[pic:([^\\s:\\]]+):([^\\]])\\]";

But none has worked for so far.

Here is a sample code:

NSString *str = @"veryLongHTMLSTRING";
NSLog(@"Original test: %@",[str substringToIndex:500]);
NSError *error = nil;
// use regular expression to replace the emoji
NSRegularExpression *regex = [NSRegularExpression
                                  regularExpressionWithPattern:@"\\[pic:([^\\s:\\]]+):([^\\]])\\]"
                                  options:NSRegularExpressionCaseInsensitive error:&error];
if(error != nil){
    NSLog(@"ERror: %@",error);
}else{
    [regex stringByReplacingMatchesInString:str
                                    options:0
                                      range:NSMakeRange(0, [str length])
                               withTemplate:[NSString stringWithFormat:@"/%@/photo/%@.gif",
                                             IMAGE_BASE_URL, @"$1/$2"]];

NSLog(@"Replaced test: %@",[str substringToIndex:500]);
  • 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-17T04:13:08+00:00Added an answer on June 17, 2026 at 4:13 am

    I see two errors: There is a + missing in the second capture group of the regex pattern, it should be

    NSString *pattern = @"\\[pic:([^\\s:\\]]+):([^\\]]+)\\]";
    

    And stringByReplacingMatchesInString returns a new string, it does not replace the matched string. So you must assign the result to a new string, or use replaceMatchesInString:options:range:withTemplate: with a NSMutableString.

    The following modifed code

    NSString *pattern = @"\\[pic:([^\\s:\\]]+):([^\\]]+)\\]";
    NSString *str = @"bla bla [pic:brand:123] bla bla";
    NSLog(@"Original test: %@",str);
    NSError *error = nil;
    NSRegularExpression *regex = [NSRegularExpression
                                  regularExpressionWithPattern:pattern
                                  options:NSRegularExpressionCaseInsensitive error:&error];
    if(error != nil){
        NSLog(@"ERror: %@",error);
    } else{
        NSString *replaced = [regex stringByReplacingMatchesInString:str
                                        options:0
                                          range:NSMakeRange(0, [str length])
                                   withTemplate:[NSString stringWithFormat:@"/%@/photo/%@.gif",
                                                 @"IMAGE_BASE_URL", @"$1/$2"]];
    
        NSLog(@"Replaced test: %@",replaced);
    }
    

    produces the output

    Original test: bla bla [pic:brand:123] bla bla
    Replaced test: bla bla /IMAGE_BASE_URL/photo/brand/123.gif bla bla
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some Quick Background I'm building an iOS app that uses html web views in
I'm building an iOS app, and part of the functionality is that it needs
I'm trying to setup a database for an iOS app I'm building to be
We are building an iOS app that uses AFNetworking to connect to a server
I am building an iOS app that is supposed to use openGraph objects for
I have an iOS app working and am trying to clean up some of
I'm building a mobile app that targets Android 2.2+, Blackberry 9+ and iOS 4+.
I am currently building an iOS app that uses Kosmaczewski's Objective-C REST client/wrapper to
I'm building a native iOS app that will allow end users to build forms
I'm currently building an iOS app via Xcode that utilises the corelocation.framework, but unfortunately

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.