regex - Javascript regexp matching integer from 1-10 following phrase -


i have string, includes not limited to

string = 'thumbnails-per-row-10-text' 

i select number after thumbnails-per-row- , integer 1 ten.

the regexp have far is:

value = string.match(/thumbnails-per-row-([1-9]|[10])/)[1] 

however, doesn't work expect, match 0 match value of '1' when looking receive value of '10'.

how can adjust regexp correctly return integer 1-10?

you can do:

/^thumbnails-per-row-(?:(?:[1-9]-)|(?:10-))text$/ 

demo

using same methodology, can expand match 1-20:

/^thumbnails-per-row-(?:(?:[1-9]-)|(?:1[0-9]-)|(?:20-))text$/ 

demo

and on...

as stated in comments (thanks wolf) can move - out of inner groups:

^thumbnails-per-row-(?:(?:[1-9])|(?:1[0-9])|(?:20))-text$ 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -