简体   繁体   中英

javascript regular expression to match a word and followed by digits

I need a regular expression to match a word exactly and immediatly followed by some digits in javascript.

In the below example url, i have to match exactly -t followed by digits 10, digits may change.

in the below url, it should match -t and 10.

priceangels.com/mouse-pads-t10.html

another example url :priceangels.com/apple-t275.html, here it should match -t followed by 275.

please help me with explanation.

试试这个正则表达式:

.*-t([\d]+).*

怎么样:

var regex = /-t\d+/;

this will satisfy for words other than t also, like

qwertu10 in priceangels.com/mouse-pads-qwertu10.html

baba10 in priceangels.com/mouse-pads-baba10.html

/(?=\-)-(\w+\d+)/g

demo here http://regex101.com/r/jN7wK2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM