1

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.

1 Answer 1

10
var matches = "Item number #8937 and #6723".match(/#\d+/g);
print(matches[0]);   // #8937
print(matches[1]);   // #6723
Sign up to request clarification or add additional context in comments.

3 Comments

I would vote the answer up, but it's too easy to deserve a vote I think.
@darkporter: That's perfectly good with me. Your vocal "vote" of confidence is very much appreciated. :-)
I can have 1 or 10 such numbers. It is not limited to 2.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.