Skip to main content
added 20 characters in body
Source Link
Richard
  • 1k
  • 1
  • 9
  • 34

This will extract number

var subject = "This is a test message [REF: 2323232]"; var onlyNum = subject.replace(/[^\d]*.*(:\s)(\d*)\]$/g,'''$2'); console.log(onlyNum)

Here, same but the number is now a real int

var subject = "This is a test message [REF: 2323232]"; var onlyNum = parseInt(subject.replace(/[^\d]*.*(:\s)(\d*)\]$/g,'''$2')); console.log(onlyNum)

This will extract number

var subject = "This is a test message [REF: 2323232]"; var onlyNum = subject.replace(/[^\d]*/g,''); console.log(onlyNum)

Here, same but the number is now a real int

var subject = "This is a test message [REF: 2323232]"; var onlyNum = parseInt(subject.replace(/[^\d]*/g,'')); console.log(onlyNum)

This will extract number

var subject = "This is a test message [REF: 2323232]"; var onlyNum = subject.replace(/.*(:\s)(\d*)\]$/,'$2'); console.log(onlyNum)

Here, same but the number is now a real int

var subject = "This is a test message [REF: 2323232]"; var onlyNum = parseInt(subject.replace(/.*(:\s)(\d*)\]$/,'$2')); console.log(onlyNum)

Source Link
Richard
  • 1k
  • 1
  • 9
  • 34

This will extract number

var subject = "This is a test message [REF: 2323232]"; var onlyNum = subject.replace(/[^\d]*/g,''); console.log(onlyNum)

Here, same but the number is now a real int

var subject = "This is a test message [REF: 2323232]"; var onlyNum = parseInt(subject.replace(/[^\d]*/g,'')); console.log(onlyNum)