Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
27
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@HorikawaTokiya

JavaScriptで数字のみ取り出す

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
27
Help us understand the problem. What are the problem?