0

I have input string like this:

let inputTest = `<div style="left: 474px; top: 550px"></div>`;

And I'm trying to get x from left: x px from above string.

I'm using regex like this one

console.log(inputTest.match(/\left:(.*)$/g));
// ["left: 474px; top: 550px"></div>"]

but it clearly start from word "left" but finish after entire string.

I want to start after 'left:' and finish before 'p' letter from px. So I will have only the number which will convert to its type (sometimes without space but will delete space after regex).

BT101
  • 3,666
  • 10
  • 41
  • 90

2 Answers2

1

To achieve expected result, use below option

inputTest.match(/left:(.*?)px/)[1]

code sample for reference

let inputTest = `<div style="left: 474px; top: 550px"></div>`;

console.log(inputTest.match(/left:(.*?)px/)[1])
Naga Sai A
  • 10,771
  • 1
  • 21
  • 40
-1

This should do it, left:.*?[\d]+

Jayendra Sharan
  • 1,043
  • 6
  • 10