How to extract the value "-1.23" from the following string using JS regex?
"hello-sdvf-1.23 23 everybody 4"
this code extracts only "-1"
("hello-sdvf-1.23 23 everybody 4").match(/[-]\d+|\d+/)[0];
您还需要定义模式以匹配小数部分。
string.match(/-?\d+\.\d+/)
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.