SQL Server doesn't have as good pattern matching abilities as regular expressions. You can search for the pattern:

[/\\][0-9]%[/\\]

That is, slash followed by a digit followed by any other string followed by a slash. This will match any characters after the first digit, but your examples have nothing of the form /1abc/.

If this is sufficient, then this does the trick:

select v.*, 
       left(v2.str2, patindex('%[/\\]%', v2.str2) - 1)
from (values ('\\servername\folder1\FTP\folder2\512/862450_FileBundle.zip')) v(str) cross apply
     (values (stuff(v.str, 1, patindex('%[/\\][0-9]%[/\\]%', v.str), ''))) v2(str2)
Answer from Gordon Linoff on Stack Overflow
🌐
SQLServerCentral
sqlservercentral.com › home › topics › urgent! - how to extract number from a string
Urgent! - How to extract number from a string – SQLServerCentral Forums
September 22, 2007 - Matt and I have done a huge amout of testing and using a RegEx "xp" in SQL Server 2000 is definitely a great way to go... On the off chance that you have a DBA that refuses to allow a "non-MS XP", there's a fairly easy way to do it... the basis of the method is covered in the same thread that Matt sited. But, for everyone's convenience, here it is... First, you need a Tally table... it's nothing more than a table with a single column of well indexed sequential numbers...
Discussions

regex - How to extract Specific Numbers from String in SQL - Stack Overflow
I am trying to extract the number present in a string in which the string comes in a different way. The String I receive and expected output is mentioned below. PRODUCT_DESCRIPTION EXPECTED PACK SIZE More on stackoverflow.com
🌐 stackoverflow.com
Help Extracting Number Code from String
Should be able to get close with substring(field, charindex(field,'(')+1, len(field)-charindex(field,'(')) More on reddit.com
🌐 r/SQLServer
8
4
May 27, 2021
Regex - extracting numbers from string in Oracle SQL - Stack Overflow
how to extract using SQL or PL/SQL all numbers from below strings? [ 6d (1.5h; 31h)] x (5 to 7) [ 1d (8h; 24h; 48.5h; 72h; 96h)] x (1 to 5) More on stackoverflow.com
🌐 stackoverflow.com
sql - Query to get only numbers from a string - Stack Overflow
I have data like this: string 1: 003Preliminary Examination Plan string 2: Coordination005 string 3: Balance1000sheet The output I expect is string 1: 003 string 2: 005 string 3: 1000 And I... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DevX
devx.com › tips › database-development › sql › extract-all-numbers-from-string-in-sql-171128153511.html
Extract All Numbers from a String in SQL
August 1, 2018 - In SQL you can use PATINDEX (which makes use of Regular Expressions) to extract all the numbers from within a string
🌐
LinkedIn
linkedin.com › pulse › how-extract-numbersletters-from-string-sql-bhaumik-patel-msuef
How to extract numbers/letters from string SQL
March 15, 2024 - We are going to learn how to extract the first numeric value from an alphanumeric string in SQL Server. DECLARE @index NVARCHAR(50); SET @index = 'CB97768.8-6304-4B7F-82A6-41825@71A4ACD'; WHILE PATINDEX('%[^0-9]%', @index) != 0 BEGIN SET @index = REPLACE(@index, SUBSTRING(@index, PATINDEX('%[^0-9]%', @index), 1), ''); END SELECT @index; -- Output : 977688630447 · If you want to get decimal number then regex need to add '.' like [^0-9.]
🌐
Data.world
docs.data.world › documentation › sql › reference › functions › regexp_extract.html
REGEXP_EXTRACT | SQL Tutorial Documentation on data.world
September 30, 2025 - A string function used in search operations for sophisticated pattern matching including repetition and alternation. For more information on the Java format for regular expressions see: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Pattern.html. ... SELECT REGEXP_EXTRACT(sales_agent, "(.*) (.*)", 2) as last_name FROM sales_teams ORDER BY last_name LIMIT 5
Find elsewhere
Top answer
1 of 2
2

You can use a regular expression and a correlated hierarchical query to get the values:

Oracle Setup:

CREATE TABLE table_name ( id, value ) AS
SELECT 1, '[ 6d (1.5h; 31h)] x (5 to 7)' FROM DUAL UNION ALL
SELECT 2, '[ 1d (8h; 24h; 48.5h; 72h; 96h)] x (1 to 5)' FROM DUAL;

Query:

SELECT id, COLUMN_VALUE
FROM   table_name t
       CROSS JOIN
       TABLE(
         CAST(
           MULTISET(
             SELECT REGEXP_SUBSTR( t.value, '\d+\.?\d*', 1, LEVEL )
             FROM   DUAL
             CONNECT BY LEVEL <= REGEXP_COUNT( t.value, '\d+\.?\d*' )
           ) AS SYS.ODCINUMBERLIST
         )
       ) n;

Results:

ID  COLUMN_VALUE
--- ------------
1   6
1   1.5
1   31
1   5
1   7
2   1
2   8
2   24
2   48.5
2   72
2   96
2   1
2   5

Query 2:

SELECT REGEXP_SUBSTR( value, '\[\s*([0-9.]+)d\s*\((.*?)\)\]\s*x\s*\(([0-9.]+)\s*to\s*([0-9.]+)\)', 1, 1, NULL, 1 ) AS days,
       REGEXP_REPLACE(
         REGEXP_SUBSTR( value, '\[\s*([0-9.]+)d\s*\((.*?)\)\]\s*x\s*\(([0-9.]+)\s*to\s*([0-9.]+)\)', 1, 1, NULL, 2 ),
         '[^0-9.;]'
       )AS hours,
       REGEXP_SUBSTR( value, '\[\s*([0-9.]+)d\s*\((.*?)\)\]\s*x\s*\(([0-9.]+)\s*to\s*([0-9.]+)\)', 1, 1, NULL, 3 ) AS x_from,
       REGEXP_SUBSTR( value, '\[\s*([0-9.]+)d\s*\((.*?)\)\]\s*x\s*\(([0-9.]+)\s*to\s*([0-9.]+)\)', 1, 1, NULL, 4 ) AS x_to
FROM   table_name t;

Results:

DAYS HOURS           X_FROM X_TO
---- --------------- ------ ----
   6          1.5;31      5    7
   1 8;24;48.5;72;96      1    5
2 of 2
1

You may derive all digits seperated by a delimiter(pipes in this case) by the contribution of regexp_replace as in the following way :

select regexp_replace('[ 6d (1.5h; 31h)] x (5 to 7)','[^0-9.]+','|') str from dual union all
select regexp_replace('[ 1d (8h; 24h; 48.5h; 72h; 96h)] x (1 to 5)','[^0-9.]+','|') from dual;

STR
------------------
|6|1.5|31|5|7|
|1|8|24|48.5|72|96|1|5|
🌐
SQLServerGeeks
sqlservergeeks.com › home › sql function to extract number from string
SQL function to extract number from string
December 20, 2019 - DECLARE @string varchar(100) SET @string = '533##dfd123fdfd111,' ;WITH T1(number) AS (SELECT 1 UNION ALL SELECT 1), T2(number) AS (SELECT 1 FROM T1 AS a cross join T1 as b), T3(number) AS (SELECT 1 FROM T2 AS a cross join T2 as b), T4(number) AS (SELECT 1 FROM T3 AS a cross join T3 as b), Nums(number) AS (SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) from T4) SELECT STUFF( (SELECT '' + SUBSTRING(@String,Nums.number,1) FROM Nums WHERE ISNUMERIC(SUBSTRING(@String,Nums.number,1))=1 FOR XML PATH('')),1,0,'') The above query breaks the string into rows of single characters and then concatenates only the rows with numeric values, thus eliminating all characters/alphabets. Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook
🌐
Pragimtech
pragimtech.com › blog › sql-optimization › sql-function-to-get-number-from-string
Sql function to get number from string
Create function UDF_ExtractNumbers ( -- Input is alphanumeric string @input varchar(255) ) -- Returns numbers as a string Returns varchar(255) As Begin -- Returns the index of a character that is not a number -- If the specified pattern is not ...
🌐
Stack Overflow
stackoverflow.com › questions › 52363450 › regex-extracting-numbers-from-string
sql - Regex - extracting numbers from string - Stack Overflow
@Cugar, I have updated the patterns to match for both REGEXP_SUBSTR calls so that the first number is returned. Still one extra null row returned. 2018-09-18T10:50:30.247Z+00:00 ... I marked first number as bold. Thanks, now it works :) 2018-09-18T11:02:09.023Z+00:00 ... How to change this SQL to also operate on case '(n=3: 0-0h, 0.05-0.05h, -0.11- -0.12h)' ?
🌐
Midtownmontgomeryliving
midtownmontgomeryliving.com › wp-content › uploads › 771fwb › 39c31a-regex-extract-number-from-string-sql
regex extract number from string sql
January 22, 2021 - The REGEXP_MATCHES() function accepts three arguments:. DECLARE @string varchar(100), @start int, Function To Extract Numbers From String Following is the syntax for the SUBSTRING() SUBSTRING() function accepts following parameters: 1.
🌐
LessThanDot
blogs.lessthandot.com › index.php › datamgmt › datadesign › extracting-numbers-with-sql-server
LessThanDot - Extracting numbers with SQL Server
December 12, 2008 - This allows us to accommodate any characters that appear before the numbers. The substring result forces the numbers to the beginning of the string. Next step is to determine where the numbers end.
🌐
Blogger
nimishgarg.blogspot.com › 2010 › 04 › oracle-sql-extract-numbers-from-string.html
Oracle: Extract Numbers from String (Ex: Pin from Address) - Oracle Database
SELECT REGEXP_SUBSTR(REPLACE(ADDRESS,' '),'[[:digit:]]{6}') FROM MYTABLE WHERE REGEXP_SUBSTR(REPLACE(ADDRESS,' '),'[[:digit:]]{6}') IS NOT NULL; Explanation: It will extract the number (6 adjcent digits) from the address field If you want to ...
🌐
GeeksforGeeks
geeksforgeeks.org › sql › regular-expression-to-extract-sql-query
SQL Data Extraction with Regular Expressions - GeeksforGeeks
July 23, 2025 - By using functions like LIKE, PATINDEX, and STUFF, we can easily validate complex data such as email addresses, extract numeric or alphabetic characters from strings, and clean up data. Understanding and applying regular expressions in SQL queries will significantly improve data validation and manipulation in our applications.