Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何编写正则表达式来提取“整数+W”值
100W abc 60W cde 40W G9 60W CA2
输出将是
100W 60W 40W 60W
[0-9]+W
那应该这样做。这是一个细分,如果你想要的话:
[0-9](匹配范围 0-9 [又名数字])
+(要求 1 个或多个先前的匹配项 [一个或多个数字,又名整数])
W(不言自明)
/\b\d+\a+/仅匹配具有单位的数字,例如100mA,而不匹配其中包含数字的单词,例如x4a.
/\b\d+\a+/
100mA
x4a