Regular expression extraction - help ;-)

I have a text with a pattern: “# 12345 XYZ123 sdfsdfsf 05-12-2019”

“12345” always consist of 5 digits.
“XYZ123 sdfsdfsf” has a arbitrary length and can be any character
“05-12-2019” is a date

I would like to extract “XYZ123 sdfsdfsf”, can a reg. expr. expert help me here :wink:

Hi buddy @jbnhf23

Kindly Try with this which could help you
This is done with split method

str_input = “# 12345 XYZ123 sdfsdfsf 05-12-2019”

Then

Str_output = Split(str_input,” “)(2).Tostring.Trim+” “+Split(str_input,” “)(3).ToString.Trim

Cheers

Hi @jbnhf23,

You can try split method like @Palaniyappan specified above. If you would like to proceed with regex, then try this pattern (?<=\d{5}\s).*(?=\s\d{1,2}-\d{2}-\d{4})

Regards,
Nimin

Thanks for both suggestions.

One minor thing. Some lines has a two dates :frowning: … for instance:

“# 12345 XYZ123 sdfsdfsf 05-12-2019 25-04-2019”

Using the regular expression, it will match the date at the end of the string. Would it be possible to match the first date

(?<=(\W){2}(\d){5}(\s))(.*?)(?=(\s(\d)+(-)(\d)+(-)(\d)+))

image
Hope that helps