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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:29:56+00:00 2026-06-02T05:29:56+00:00

My current regex battle is replacing all commas before a number in a string.

  • 0

My current regex battle is replacing all commas before a number in a string. The regex must then ignore all following commas. I’ve been screwing around on rubular for about an hour and can’t quite seem to get something working.

Test String…

'this is, a , sentence33 Here, is another.'

Desired Output…

'this is comma a comma sentence33 Here, is another.'

So something along the lines of…

testString.gsub(/\,*\d\d/,"comma")

To give you some background, I’m doing a little scraping sideproject. The elements I’m gathering are largely comma separated beginning with a two digit age. However sometimes theres a headline preceeding the age that may contain commas. To preserve the structure I set up later on, I need to replace the commas in the headline.

AFTER TRYING STACK OVERFLOW’S ANSWER…

I’m still having some issues. Don’t laugh but here’s the actual line from the screen scraping thats causing problems…

statsString =     "              23,  5'9\",  140lb,  29w,                        Slim,                 Brown       Hair,             Shaved Body,              White,    Looking for       Friendship,    1-on-1 Sex,    Relationship.   Out      Yes,SmokeNo,DrinkNo,DrugsNo,ZodiacCancer.      Versatile,                  7.5\"                    Cut, Safe Sex Only,     HIV      Negative, Prefer meeting at:Public Place.                   PerformerContact  xxxxxx87                                                   This user has TURNED OFF his IM                                     Send Smile      Write xxxxxx87 a message:" 

First to all of these fragments I add ‘xx, ‘ so that my comma filtering will work in all cases, those with and without text ahead of the age. Followed by the actual fix. The output is below…

statsString = 'xx, ' + statsString

statsString = statsString.gsub(/\,(?=.*\d)/, 'comma');

 => "xxcomma               23comma  5'9\"comma  140lbcomma  29wcomma                        Slimcomma                 Brown       Haircomma             Shaved Bodycomma              Whitecomma    Looking for       Friendshipcomma    1-on-1 Sexcomma    Relationship.   Out      YescommaSmokeNocommaDrinkNocommaDrugsNocommaZodiacCancer.      Versatilecomma                  7.5\"                    Cutcomma Safe Sex Onlycomma     HIV      Negativecomma Prefer meeting at:Public Place.                   PerformerContact  xxxxx87                                                   This user has TURNED OFF his IM                                     Send Smile      Write xxxxxxx87 a message:" 
  • 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-06-02T05:29:59+00:00Added an answer on June 2, 2026 at 5:29 am

    Code:

    testString = 'this is, a , sentence33 Here, is another.';
    result = testString.gsub(/\,(?=.*\d)/, 'comma');
    print result;
    

    Output:

    this iscomma a comma sentence33 Here, is another.

    Test:

    http://ideone.com/9nt1b

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

Sidebar

Related Questions

/<table[\s]+cellspacing=0[\s]+class=cj(?:.*?)[\s]+id=(?:.*?)>(?:.*?)value=(.*?)(?:.*?)<td[\s]+class=dep>(.*?)<\/td>(?:.*)(?:<td[\s]+class=arr>(.*?)<\/td>)+(?:.*?)<\/table>/ This is my current regex string, used in PHP with preg_match_all() . I
Problem: Current regex pattern does not filter all lines. Adding ^ to the beginning
Can I use a javascript regex to count the number of whitespace characters before
I have the following regex: String regExpression = ^[a-zA-Z0-9+,. '-]{1,+maxCharacters+}$; which works fine for
Current I have a seperate maven module for my database access, all my DAO
Current Regex: ^([\d-]*[A-z]?|[A-z]?[\d-]*|[\d-]*[A-z]?[\d-]*){3}$ (Allows a max of 3 letters and any amount of numbers
I'm using a regex to match Bible verse references in a text. The current
I am currently using this regex to get the page number from the url:
I need a regex for a password which meets following constraints in my rails
My current regex is /^[a-zA-Z]+( [a-zA-Z]+)*$/ . It works for names like: John Smith

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.