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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:08:38+00:00 2026-05-12T21:08:38+00:00

I have the following jquery statement. I wish to remove the whitespace as shown

  • 0

I have the following jquery statement. I wish to remove the whitespace as shown below. So if I have a word like:

For example

  • #Operating/System I would like the
    end result to show me
    #Operating\/System. (ie with a
    escape sequence).

  • But if I have #Operating/System test then I want to show
    #Operating\/System + escape
    sequence for space. The .replace(/ /,'')
    part is incorrect but .replace("/","\\/") works
    well as per my requirements.

Please help!

$("#word" + lbl.eq(i).text().replace("/","\\/").replace(/ /,'')).hide();
  • 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-12T21:08:38+00:00Added an answer on May 12, 2026 at 9:08 pm
    $( "#word" + lbl.eq(i).text().replace(/([ /])/g, '\\$1') ).hide();
    

    This matches all spaces and slashes in a string (and saves the respective char in group $1):

    /([ /])/g
    

    replacement with

    '\\$1'
    

    means a backslash plus the original char in group $1.

    "#Operating/System test".replace(/([ /])/g, '\\$1');
    -->
    "#Operating\/System\ test"
    

    Side advantage – there is only a singe call to replace().

    EDIT: As requested by the OP, a short explanation of the regular expression /([ /])/g. It breaks down as follows:

    /           # start of regex literal
      (         # start of match group $1 
        [ /]    # a character class (spaces and slashes)
      )         # end of group $1
    /g          # end of regex literal + "global" modifier
    

    When used with replace() as above, all spaces and slashes are replaced with themselves, preceded by a backslash.

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

Sidebar

Related Questions

I have the following jQuery statement: $.ajax({ type: POST, url: db.php, data: word=+ tmpWord,
I have the following JQuery statement and it is adding the class 'current' but
I would like to write an If Statement in jQuery that will accomplish the
I have the following jQuery statement which works fine but I was wondering if
i have jquery global error event set, like following: $(#message_alert).ajaxError(function(event, XMLHttpRequest, settings, thrownError){ ajax_error(XMLHttpRequest);
I have the following jQuery: $(document).ready(function () { $(.element).draggable(); $(.element).droppable({ drop: function () {
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following jQuery: $(this).closest('div.mcoup').find('div.delcoup').slideToggle(400) .siblings().children('div.delcoup').slideUp(400); What I'm trying to do is get
I have the following jQuery code which runs when I'm clicking an option in
I have the following jquery function for filtering the contents of a listbox on

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.