Skip to content Skip to sidebar Skip to footer

Filter A Part Of An Url That Goes Like Image-123-123 Regex

I need to get the generated size of an image in wordpress using Javascript, the url looks like this: wp-content/uploads/2018/04/image-300x200.jpg and i need to get only the value

Solution 1:

Simply do \d+x\d+ or:

\d+x\d+(?=\.jpg)

This uses a look ahead (?=) to match every \d+x\d+ when it appears before .jpg

Solution 2:

use this:

/(\d+?x\d+?)\./

according to format NumbersxNumbers.

console.log('wp-content/uploads/2018/04/image-300x200.jpg'.match(/(\d+?x\d+?)\./)[1])

Post a Comment for "Filter A Part Of An Url That Goes Like Image-123-123 Regex"