Regex from several words

Hello,

I want to integrate a regex into my process that would allow checking the name of a file:
Example:
Log_rapport_OVE1_20251014_202118.zip
In this file name, I would like to check the presence of these three criteria:

  • Prefix “Log”
  • Presence of the date that will be a variable (“20251014”)
  • Extension “. zip”

Thank you in advance for your help

Hi @Julien_Horreau

You can try the following regex.

Log.*\d{8}.*\.zip

Regards.

If you want to check the date more clearly, you can use the following.

Log.*[0-9]{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01]).*\.zip

Regards.

thank you, but I want my date to match an input variable

@Julien_Horreau

then use like this

str_name.startswith("Log") str_extension.Equals("zip") generally extension variable will be separate..orelse can check with endswith

and date check for contains str_Nmae.contains(datetocheck)

cheers

1 Like

Ok. I got it now. Then you can use the following logic:

Dim pattern As String = "Log_.*_" & yourDate & "_\d{6}\.zip"
If System.Text.RegularExpressions.Regex.IsMatch(fileName, pattern) Then
    isValid = True
Else
    isValid = False
End If

Hope this helps.

1 Like

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