I am working with a stored procedure where I am getting a string with different characters I want to get a value at last index
[AV] Z_Prem_454-3000_XXXXX_800+ [InstalmentScheme 6]
above is the string I am getting from a external db
I want the value of instalmentscheme which is 6 above
I am currently sending the above whole string from stored procedure to C# code and there I have written a extension method called extract which gets above string and gets the value of the instalemntscheme code I don't know this will work if value is null or sometimes null
public static string Extract(string input)
{
if (string.IsNullOrEmpty(input)) return null;
var lastIndex = input.LastIndexOf(' ');
if (lastIndex < 0) return "";
var code = input[lastIndex..^1].Trim();
return CheckingIfNumber(code) ? code : null;
}
I want to do it in SQL itself so that I can send that to C# code directly.
\[InstalmentScheme \d+\]$. You can capture just the number into a capture group with\[InstalmentScheme (\d+)\]$and even give it a name so you can access it by name\[InstalmentScheme (?<scheme>\d+)\]$