Nick Vanderbilt
Nick Vanderbilt

Reputation: 38540

Regular Expressions in JavaScript

I need to get all the numbers that start with #.

"this is sentence 1 . Item number #4567 "

"this is sentence 2. Item number #8937 and #6723"

I am using JavaScript.

Using regular expression how do I get all the numbers in a string.

Upvotes: 1

Views: 145

Answers (1)

C. K. Young
C. K. Young

Reputation: 223183

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

Upvotes: 10

Related Questions