-1

I have the following code and want to be able to only return 10 characters after the 'LAST='. If there isn't 10 chars then don't return anything.

const value = 'LAST=uirndheusnrm38f6xxxxxxx'
const m = value.match(/LAST=([^\?&]+)/i)

if (m)
{
  console.log('i know it matched LAST= and returned the next 10 chars')
}

Is it possible without doing a substr(0,10) ?

i cant code
  • 305
  • 2
  • 7

1 Answers1

1

In order to match exactly 10 characters we can use {10}:

const m = value.match(/LAST=([^\?&]{10})/i);
Aplet123
  • 33,825
  • 1
  • 29
  • 55