LoginSignup
53
32

More than 3 years have passed since last update.

JavaScriptで数字のみ取り出す

Last updated at Posted at 2018-10-26

JavaScriptで正規表現を使って数字だけ取り出す。

const data = 'hoge123';
const res = data.replace(/[^0-9]/g, '');

console.log(res); // 123

g  すべての一致に対して置換を実施。

gが大事みたいっす。

参考
http://mypaceprogram.blogspot.com/2017/11/javascript.html

53
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
53
32