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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:51:46+00:00 2026-05-31T04:51:46+00:00

this is my first post to stackoverflow, but I’ve used this amazing site before.

  • 0

this is my first post to stackoverflow, but I’ve used this amazing site before.

Anyway, I suck at regular expressions but I think I need them for what I need to do.

Short Question:
I need to replace the space ' ' with '&nbsp;' between any occurrence of <code></code>.

More details:

The motivation behind this was because my code sections were creating extra lines every other line because of the extra spaces (I’m asuming). By replacing the spaces with &nbsp;, I was able to format the code correctly.

However, this introduced a LOT of extra characters into my HTML. Not only is it inefficient, it also makes word-wrap: break-word; break the words in half rather than move the entire word down.

  • 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-31T04:51:48+00:00Added an answer on May 31, 2026 at 4:51 am

    disclaimer: in no way do i think this is the solution you will neccessarily arrive at, some other answers already here address what you *should/could otherwise do to accomplish your task.

    but let’s just assume you DID want to do it with regex. Since I think we can make the assumption that with <code>stuff</code>, stuff won’t contain nested code tags, you can accomplish your short question with it, but you still need a couple steps:

    //sorry for the c#, the but intent should translate clearly.
    string input = @"<div>whatever</div> id='tricky'><code>adsfasd   fasdfasdfvar data = "" 8 5.00000000 8.0 9.000000"";var re = /(\.0{0,2})(0*)/g; var match = re.exec(data);alert(data.replace(re, RegExp.1));</code><p>more stuff with stuff.</p>";
    var code = Regex.Match(input, "<code>(.*?)</code>").Value;
    var munged = Regex.Replace(code, @"\s", "&nbsp;");
    var result = Regex.Replace(input, "<code>(.*?)</code>", munged); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello stackoverflow guru's! This is my first post after having used the site for
this is my first post here on stackoverflow and am very impressed by the
this is my first post on this website, but I'm all the time getting
Well, this is my first post here and really enjoying the site. I have
This is my first post to stackoverflow, so bear with me. :) I am
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might
This is my first post on stackoverflow, hello everyone! My first venture into jQuery
this is my first post here on StackOverflow and I'm quite excited about it
First, I must say that I have read several post about this at StackOverflow
Before you mark this as answered in another post (I already saw those). But

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.