
[英]trying to get a regex match in javascript with certain letter followed by any number
[英]Regex - match a certain number of numeric when followed by letter
我想匹配一个字符串,它是1-4个数字,后跟一个特定的字母。
例如,如果我的字符串是
'这种橡胶的硬度是90a,另一种的硬度是120a'
我想抓住'90a'和'120a'的值。
我试过^[0-9]{0,4}[a]$
和^([0-9]{0,4})[g]$
奖励积分,如果它可以匹配数字后面的空格。 例如/
'橡胶1号是98 a,橡胶2号是89 a'
会匹配
'98 a'
和
'89一个'
没问题:
\b\d{1,4} *a\b
说明:
\b # Start of number (or use (?<!\d) if you're not on JavaScript)
\d{1,4} # Match 1-4 digits
[ ]* # Match optional space(s)
a # Match the letter "a"
\b # Make sure no letter/digit follows
这将匹配
(\d{1,4} \s*\w)
\d+ for one or more numbers
\s* for zero or more spaces
\w for a character
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.