Huy Vo
Huy Vo

Reputation: 3

Regular expression ends with specific character but ignore it

console.log("1h2m3s".match(/\d+h/i));

The code results in 1h but I want just the number it self. I could cut off the end, but I don't want to do that. How do I just isolate just the number part?

Upvotes: 0

Views: 35

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521103

You could use a positive lookahead instead which checks for the h component:

console.log("1h2m3s".match(/\d+(?=h)/i));

Upvotes: 1

Related Questions