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+
Answer from Seattle Leonard on Stack Overflowif 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+
^\s*(\w+)\s*\(\s*(\d+)\D+(\d+)\D+\)\s*$
should work. After the match, backreference 1 will contain the month, backreference 2 will contain the first number and backreference 3 the second number.
Explanation:
^ # start of string
\s* # optional whitespace
(\w+) # one or more alphanumeric characters, capture the match
\s* # optional whitespace
\( # a (
\s* # optional whitespace
(\d+) # a number, capture the match
\D+ # one or more non-digits
(\d+) # a number, capture the match
\D+ # one or more non-digits
\) # a )
\s* # optional whitespace
$ # end of string
How to extract numbers within a string?
Extract Number After Certain Word With Regex
RegEx extract numbers before and after text string
Regex to extract string and number
Hi I am new to Python but am working on a project where I want to extract numbers from a string. For example I have the string "CORSAIR VENGEANCE RGB 16GB (2X8GB) DDR4 3200MHZ CL 16" where I want to extract the "16" from "16GB" as well as the "2" and "8" in "(2x8GB)" and "3200" from "3200MHZ".
What is the best way to do this? Thanks in advance!
Edit: Thanks everyone for the help! Regex seems to help do the trick
Extract all the numbers from string and output their SUM. I’m struggling to achieve same using REGEX in powershell
String ='“Total Facility A Commitments” means the aggregate of the Facility A Commitments, being £2,500,000 at the date of this Agreement.
“Total Facility B Commitments” means the aggregate of the Facility B Commitments, being £2,500,000 at the date of this Agreement.
“Total Facility C Commitments” means the aggregate of the Facility C Commitments, being £2,500,000 at the date of this Agreement.
[“Total Incremental Facility Commitments” means, in relation to an Incremental Facility, the aggregate of the Incremental Facility Commitments relating to that Incremental Facility.] ’
Output = £7,500,000
You said you are struggeling, what have you tried so far?
Please share your code so we can help.
You can use the ‘-match’ operator and then look for numbers in the string.
If you post code, please use the insert code button! Please and thank you!
Hi, and welcome to the PowerShell forum! Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! Use a descriptive subject. Don't say "Need help" or "PowerShell Help", actually summarize what the problem is. It helps the rest of us keep track of which problem is which. Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy, past…

Try this simple method too:
string input = "ABC3454 ";
string output = string.Concat( input.Where( Char.IsDigit ) );
If this is for SQL-Server, you can create a function e.g.
CREATE FUNCTION dbo.udf_GetNumeric
(
@strAlphaNumeric VARCHAR(256)
)
RETURNS VARCHAR(256)
AS
BEGIN
DECLARE @intAlpha INT
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)
BEGIN
WHILE @intAlpha > 0
BEGIN
SET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )
SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric )
END
END
RETURN ISNULL(@strAlphaNumeric,0)
END
GO
To create the function, create a new query, add the code above and execute it. Best done in SSMS (SQL-Server Management Studio)
And here I use it on a column that has alphanumeric values. ShipAddress is the original and ShipAddressNumbersOnly uses the function.