How to extract numeric value when the string format is not predictable?

I have following strings in a column -

GD45637 24/03/2020
GD #34567 (03-03-2020)

I want to get the numeric part of the string -
45637
34567

I tried to use split with a " " but that doesn’t work for the second string.

Could anyone help me acheive this requirement?

Hi,

If there is no other 5 digit number, the following expression will work.

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=\D)\d{5}(?=\D)").Value

Regards,

Hi Yoichi, Thanks for your reply. The problem is the length of the numeric portion of the string is also variable. Only Constant is the initial ‘GD’

Hi,

Only Constant is the initial ‘GD’

How about the following?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=GD\W*)\d+(?=\s)").Value

Regards,

1 Like

Amazing!!! it works!!! I have tested with 5-7 variants. Thank you so much!! Stay Safe!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.