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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:50:57+00:00 2026-06-08T05:50:57+00:00

Why does var a = 1ab; a = a.replace(/[^\d][a-z]/g, ); remove a and b?

  • 0

Why does

var a = "1ab";
a = a.replace(/[^\d][a-z]/g, "");

remove “a” and “b”? I thought that it should remove only “b” because “a” is preceeded by a number which I excluded by [^\d].

Who can help me?

  • 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-08T05:50:59+00:00Added an answer on June 8, 2026 at 5:50 am

    It removes them because your character class [^\d] means “anything that is not a digit.” The ^ means “not” and \d means “digit”. So your expression means “match anything that is not a digit followed by any lowercase letter”, which matches "ab".

    To remove only lowercase letters that don’t have a digit in front of them, it’s probably easiest to do it with a capture group:

    a = a.replace(/([\d][a-z])[a-z]/g, "$1");
    

    That says: Match a digit followed by a lowercase letter (as a group) followed by a lowercase letter (outside the group), and replace it with just the group’s contents. If you want to remove "c" from "1abc", add a + after the last [a-z], e.g.: /([\d][a-z])[a-z]+/g.

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

Sidebar

Related Questions

Does anyone know of a Java library that provides support for the ${var} style
var object = {foo: 'bar'}; Does JavaScript have a way to determine that object.foo
why does this only alert 1 ? function test() { var myobj = {
I have Javascript code that does this: var oObjchbox = document.getElementById(CheckBox_ + countyId); The
I have a third party JQuery library that does this: var $this = $(this);
I have the following code, which does work: var dataSource = (from p in
I came across this file on github, which does this: var migrate = require('../')
I'm working with some code that does this: var _init = false; this.init =
Possible Duplicate: What does var that = this; mean in javascript? I often find
I have a php ternary operator as follows that does not work: var newLoginTxt

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.