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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:37:51+00:00 2026-05-22T19:37:51+00:00

Does anyone have a good regex to do this? For example: This is *an*

  • 0

Does anyone have a good regex to do this? For example:

This is *an* example

should become

This is <b>an</b> example

I need to run this in Objective C, but I can probably work that bit out on my own. It’s the regex that’s giving me trouble (so rusty…). Here’s what I have so far:

s/\*([0-9a-zA-Z ])\*/<b>$1<\/b>/g

But it doesn’t seem to be working. Any ideas? Thanks 🙂

EDIT: Thanks for the answer 🙂 If anyone is wondering what this looks like in Objective-C, using RegexKitLite:

NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:@"\\*([0-9a-zA-Z ]+?)\\*" withString:@"<b>$1<\\/b>"];

EDIT AGAIN: Actually, to encompass more characters for bolding I changed it to this:

NSString *textWithBoldTags = [inputText stringByReplacingOccurrencesOfRegex:@"\\*([^\\*]+?)\\*" withString:@"<b>$1<\\/b>"];
  • 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-22T19:37:52+00:00Added an answer on May 22, 2026 at 7:37 pm

    You’re only matching one character between the *s. Try this:

    s/\*([0-9a-zA-Z ]*?)\*/<b>$1<\/b>/g
    

    or to ensure there’s at least one character between the *s:

    s/\*([0-9a-zA-Z ]+?)\*/<b>$1<\/b>/g
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone use have a good regex library that they like to use? Most
Does anyone have a good (preferably tested) regex for accepting only a valid DNS
Does anyone have a good example of a WPF or silverlight windows gadget?
Does anyone have a good shell line for this? I want to check the
Does anyone have a good regex for stripping all symbols (';.,_\$@!% the carriage return
Does anyone have a good example of creating a WPF custom control or some
Does anyone have a good example for common error handling for service calls? I
Does anyone have a good way to build MSI (vdproj) projects using MsBuild or
Does anyone have some good hints for writing test code for database-backend development where
Does anyone have any good starting points for me when looking at making web

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.