-2

now I begin learning regex, and I have set of string in format like "(9/13)", and I need get second number. I try this regex: /\(.*?[^\d]*(\d+?)\)/g, in online regex it works normally.

But here:

var d = "(9/13)";
var v = /\(.*?[^\d]*(\d+?)\)/g;
alert(d.match(v));

it returns "(9/13)" , what am I doing wrong?

Eldos Narbay
  • 319
  • 4
  • 12
  • You really could just use https://regex101.com/r/mFGYcA/2/codegen?language=javascript and keep only what you need. If you are using regex101, use all of its power. – Wiktor Stribiżew Aug 22 '17 at 11:03

2 Answers2

1

const source = "(9/13)";

const re = /\/(\d+)\)/;

console.log('result', re.exec(source).pop())
Hitmands
  • 13,491
  • 4
  • 34
  • 69
0

you can use Regex.exec() to find the number

const source = "(9/13)";

const re = /\(\d+\/(\d+)\)/;

console.log(re.exec(source)[1])
marvel308
  • 10,288
  • 1
  • 21
  • 32