// Change of the text for better test results var subject = "This"hjavsdghvwh isjgya a16162vjgahg451514vjgejd5555v testfhgv messagef [REF:262641hvgf 2323232]";665115bs cj15551whfhwj511"; var regex = /\d+/g; let number = subject.match( regex ) console.log(number) It Will return array for now, and if no match found, it will return null. For most of the time, when i used this regex i get perfect result unless if string contains decimal values.