简体   繁体   English

JavaScript中的正则表达式

[英]Regular Expressions in JavaScript

I need to get all the numbers that start with #. 我需要获取所有以#开头的数字。

"this is sentence 1 . Item number #4567 " “这是句子1。商品编号#4567”

"this is sentence 2. Item number #8937 and #6723" “这是句子2。商品编号#8937和#6723”

I am using JavaScript. 我正在使用JavaScript。

Using regular expression how do I get all the numbers in a string. 使用正则表达式如何获取字符串中的所有数字。

var matches = "Item number #8937 and #6723".match(/#\d+/g);
print(matches[0]);   // #8937
print(matches[1]);   // #6723

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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