[英]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. 我需要一个正则表达式来准确匹配一个单词,然后立即跟随javascript中的一些数字。
In the below example url, i have to match exactly -t followed by digits 10, digits may change. 在下面的示例url中,我必须完全匹配-t后跟数字10,数字可能会改变。
in the below url, it should match -t and 10. 在下面的url中,它应匹配-t和10。
priceangels.com/mouse-pads-t10.html priceangels.com/mouse-pads-t10.html
another example url :priceangels.com/apple-t275.html, here it should match -t followed by 275. 另一个例子url:priceangels.com/apple-t275.html,这里应匹配-t后跟275。
please help me with explanation. 请帮我解释一下。
试试这个正则表达式:
.*-t([\d]+).*
怎么样:
var regex = /-t\d+/;
this will satisfy for words other than t
also, like 这也将满足除了
t
其他词语
qwertu10
in priceangels.com/mouse-pads-qwertu10.html
qwertu10
在priceangels.com/mouse-pads-qwertu10.html
baba10
in priceangels.com/mouse-pads-baba10.html
baba10
in priceangels.com/mouse-pads-baba10.html
/(?=\-)-(\w+\d+)/g
demo here http://regex101.com/r/jN7wK2 演示http://regex101.com/r/jN7wK2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.