4
Answers

need to help retrieve numeric values with dot

Ask a question
mahi babu

mahi babu

12y
1.6k
1
Hi,

Please help me in regular expression in c# code:

Input:                      AB12(100).HJI(20).D76R(222)
Expected Output:   100.20.222           ( Integer only in brackets append with dot(.))

Current output:      1210076222

Please find my code below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;

namespace CLRPlay
{
    public partial class UserDefinedFunctions
    {
	static readonly Regex _regex = new Regex(@"[^0-9]*", RegexOptions.Compiled);
        static readonly string _nR = @"";
       
        [Microsoft.SqlServer.Server.SqlFunction]
        public static SqlString Indexkey(SqlString val)
        {
            if (val.IsNull) return SqlString.Null;
            return _regex.Replace(val.ToString(), _nR);
        }
    };
}

Answers (4)