53
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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
33
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
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?