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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:17:12+00:00 2026-06-18T14:17:12+00:00

I just suck at regex. I’ve been reading at http://www.regular-expressions.info/tutorial.html but I can’t figure

  • 0

I just suck at regex. I’ve been reading at http://www.regular-expressions.info/tutorial.html but I can’t figure out how to write this.

I have a string that contains 2 numbers (days of the month with leading 0s). I’m trying to remove the leading 0s from the string but not remove the 0 in “10” or “20”.

example strings that could be here:
“01”,”02″,”03″,”10″,”11″,”12″,”20″,”31″

since the string is always a day of the month, it will always be 2 characters in length and always between 01 and 31.

currently I’m using this (which is obviously wrong):

string.replace(/0/,'');

What I’m trying to end up with is this:
“1” instead of “01”, “2” instead of “02”, “10” without losing the “0”.

Hopefully this is clear enough.

How do I do this correctly?

  • 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-18T14:17:13+00:00Added an answer on June 18, 2026 at 2:17 pm

    If the string only contains the number you could just convert it to an integer, eg:

    var num = +str;
    

    If you want to replace parts of a larger string, you can use \b:

    str.replace(/\b0+\B/g, '');
    

    Example:

    "i have 000100 and 0020!".replace(/\b0+\B/g, '')
    

    Returns:

    "i have 100 and 20!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tried to do this but I just suck at regular expressions. What I
So out of all of my php skills, I just suck at regular expressions.
Just a simple question, but can't get an answer on my own. In memory
Just switched from apache and having some rewrite issues. Simple task: rewrite http://www.foo.com/BAR/ to
So, maybe I just suck at searching, but I'm having real trouble finding a
Okey I got two questions. Number one. I really suck at regex, it just
Alright, turns out I suck at Encryption/Decryption. I just dont get it. How can
Just checking my JS and I have an error, but I cannot see where.
Possible Duplicate: How can I get a regex to check that a string only
what i need, might be quite simple to do with jQuery, I just suck

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.