jbnhf23
(Jesper Hansen)
July 7, 2019, 5:35pm
1
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
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
nimin
(nimzz)
July 7, 2019, 6:05pm
3
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
jbnhf23
(Jesper Hansen)
July 7, 2019, 6:53pm
4
Thanks for both suggestions.
One minor thing. Some lines has a two dates … 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
ashley11
(Ashley Nihal Dcunha)
July 7, 2019, 7:01pm
5
jbnhf23:
12345 XYZ123 sdfsdfsf 05-12-2019
jbnhf23:
12345 XYZ123 sdfsdfsf 05-12-2019 25-04-2019”
(?<=(\W){2}(\d){5}(\s))(.*?)(?=(\s(\d)+(-)(\d)+(-)(\d)+))
Hope that helps