Grow your CSS skills. Land your dream job.

Last updated on:

Strip Numbers from a String

var someString = "Hello 123 World!";

newString = someString.replace(/[0-9]/g, '');

// console.log(newString);
// "Hello  World!";

Comments

  1. Permalink to comment#

    I don’t think I’ve ever use regex in javascript. Thanks for the reminder that you can!

  2. Permalink to comment#

    Thanks for this nice tip of using regex

  3. The same thing can be achieved with:

    var someString = “Hello 123 World!”;
    newString = someString.replace(/\d+/g, ”);

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".