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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:28:35+00:00 2026-05-18T08:28:35+00:00

I am trying to replicate WMD Markdown Editor. I tried to modify WMD instead

  • 0

I am trying to replicate WMD Markdown Editor. I tried to modify WMD instead of reinventing the wheel but its code is not readable to me …

So I am trying to allow removing of italics “*” but not bold “**“

So, the italics below should be removed

this *is a* test
this ***is a*** test

But the below should be untouched

this **is a** test

I guess I should use RegExp but how? How do I match the * only if its “alone” or is followed by 2 or more *s

  • 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-18T08:28:36+00:00Added an answer on May 18, 2026 at 8:28 am

    This is hard to solve with straight regexp, especially handling edge cases where the asterisks are at the beginning or end of the string. Mixing some regexp magic with some replace magic gets the job done though…

    function removeItalics(str) {
        var re = /\*+/g;
        return str.replace(re, function(match, index) { return match.length === 2 ? '**' : ''; });
    }
    
    alert(removeItalics("this *is a* test"));     // this is a test
    alert(removeItalics("this **is a** test"));   // this **is a** test
    alert(removeItalics("this ***is a*** test")); // this is a test
    

    We’re matching runs of one or more asterisks. Matches are greedy. So the longest run of asterisks will be matched. If the length of the match is 2, we put the asterisks back, otherwise we strip them.

    Working example is here: http://jsfiddle.net/QKNam/

    UPDATE: If you want to keep bold if you have 2 or more asterisks, just change the match.length logic like this…

    function removeItalics(str) {
        var re = /\*+/g;
        return str.replace(re, function(match, index) { return match.length === 1 ? '' : '**'; });
    }
    
    alert(removeItalics("this *is a* test"));     // this is a test
    alert(removeItalics("this **is a** test"));   // this **is a** test
    alert(removeItalics("this ***is a*** test")); // this **is a** test
    

    Updated jsFiddle: http://jsfiddle.net/QKNam/3/

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

Sidebar

Related Questions

I'm trying to replicate the following Ninject syntax in Unity, but not having any
I'm trying to replicate a UI like a gcalendar (only the layout not any
I am trying to replicate the animated drop down menu here but I am
I'm trying to replicate the browser post parameters on http://www.ebayclassifieds.com/m/PostAd?scrid=3465450-2253858851033189948 but for some reasons
I am trying to replicate, with my own code, the history-sniffing demo seen on
I'm trying to replicate the Convert.ToBase64String() behavior in Ruby. Here is my C# code:
I'm trying to replicate this functionality in SharePoint 2010. I've added Content Editor web
I'm trying to replicate some C# code in PHP5 and am having some difficulties.
Trying to replicate the docking controls in Visual Studio 2008. My application replays the
Im trying to replicate an effect as seen on http://www.fiat.co.uk/Showroom/#showroom/punto_evo/explore . I have made

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.