I am working with string as below:
DOT LTB TOL SP BLM 3X(35X**25.1**GR)BWY BNL
And I am trying to extract the float between the last X and G -> 25.1.
In Python it is an easy task using regex expression: **[0-9]+X([0-9\.]+)G**
But I could not find a way to extract the data here in SQL Server:
I tried to write a function that define the position of X and the ) argument like that:
AS
Begin
Declare @LastX as INT
Declare @LastG as INT
Declare @Diff as INT
Declare @Result as varchar(50)
Set @LastX = LEN(@Temp) - CAST(CHARINDEX('X', REVERSE(@Temp)) AS Integer)
Set @LastG = LEN(@Temp) - CAST(CHARINDEX(')', REVERSE(@Temp)) AS Integer)
Set @Diff = @LastG - @LastX
IF @Diff > 0
Set @Result = SUBSTRING(@Temp, @LastX, @Diff)
ELSE
Set @Result = 0
Return @Result
End
My result is 5X25.1G
Can you help me with this?
I'm also open if you have other suggestion to extract this value in SQL.