Alex Rivera | Logout

Regular expression to extract numbers from a string

Asked 2010-11-15T17:56:17.200
40

Can somebody help me construct this regular expression, please...

Given the following strings...

  • "April ( 123 widgets less 456 sprockets )"
  • "May (789 widgets less 012 sprockets)"

I need a regular expression that will extract the two numbers from the text. The month name will vary. The brackets, "widgets less" and "sprockets" text are not expected to change between strings, however, it would be really useful if this text was able to be varied as well.

Edit
Report

1 Answer

76

if you know for sure that there are only going to be 2 places where you have a list of digits in your string and that is the only thing you are going to pull out then you should be able to simply use

\d+
answered 2010-11-15T18:02:40.867

Your Answer