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

  • Home
  • SEARCH
  • 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 509619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:01:46+00:00 2026-05-13T07:01:46+00:00

Hey, I am using a reg expression to remove parentheses and the content between

  • 0

Hey, I am using a reg expression to remove parentheses and the content between them from a ruby string. The problem is that this sometimes leaves a space before commas. I am not sure how to go about removing this space. I’ve been playing around with the following but it has not been working:

 @char_count = 0
 sentance.each_char{|char| 
   if char == ","
     if sentance[@char_count-1] == 32
       sentance[@char_count-1] = "" 
     end
   end
   @char_count += 1
 }

Any help is appreciated!

Edit: sentance.gsub!(/ ,/, ‘,’) is working well, but now I am realizing that there are some places where there are multiple spaces before a comma. I need to account for this scenerio as well.

  • 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-13T07:01:46+00:00Added an answer on May 13, 2026 at 7:01 am

    You can use the gsub method of the string class to do this.

    s = "this is a string, with some commas with spaces in front ,1 ,2 ,3"
    s.gsub(/ ,/, ',')
    "this is a string, with some commas with spaces in front,1,2,3"
    

    gsub will return a new string with the space , string replaced by a comma. gsub! will change the string in place.

    If you sometimes have multiple spaces with a trailing comma then you may wish to use a slightly modified regex to catch the multiple spaces

    s.gsub!(/ +?,/, ',')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 308k
  • Answers 308k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should only need to add the style to A.… May 13, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer This is equivalent to the Csc.exe /define: (or vbc.exe if… May 13, 2026 at 9:41 pm
  • Editorial Team
    Editorial Team added an answer Javascript doesn't work across different web page. You need to… May 13, 2026 at 9:41 pm

Related Questions

Hey I am using a NSURL Connection to receive data. [NSURLConnection sendSynchronousRequest: //create request
Hey, i am looking for a method to creat temporay thumb file in PHP.
I am using a search library which advises keeping search handle object open for
I am using XAMPP on a localhost windows VISTA m/c...using gmail as smpt server
Hey, I am using iBATIS with SQL Server Compact Edition 3.5 and try to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.