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 at least some of the functionality of Workgroup Manager using
I've been trying to replicate the limit and range feature provided in MySql in
I'm trying to demonstrate to our QA department that we have (or have not)
I have a LinearLayout view that I am trying to add a divider to
I've started to learn Haskell and feeling overwhelmed with it. I'm now trying to
I have an asp:ListBox control on my web page. I am trying to select
I have read quite a lot of R docs, but I can't find anything
I'm trying to replace in VIM all multiple - characters (from the start of
I am trying to automate my deployment process and am now thoroughly confused. I
i have been playing around with apache SOLR since last 3 weeks and very

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.