How to separate letters and numbers from a string in JavaScript

I have a string that is a combination of letters and numbers. For my application, I need to separate the line with letters and numbers: ex: If my line is "12jan", I want the "12" "jan" separately.

+3
source share
2 answers

You can always do this if stryour line is:

var digits = str.replace(/\D/g, ""),
    letters = str.replace(/[^a-z]/gi, "");   

Essentially, this code does the replacement of all characters that you don't want with an empty string.

\D [^a-z] , , , -. g . i , .

+5

, ,

parseInt(num)

parseInt(12Jan); 12.

, , .

+1

Source: https://habr.com/ru/post/1777608/


All Articles