Regex Split

Hi, what would be the regex split I should use to get the date from this path?
I modified the path for illustration purposes. I would like to have 01-31-2023. Thank you!

C:\Users\MESSI\OneDrive - Inter\Documents\Messi L\MIB\MIB-2022 for 2023\2023\Player Count\Player Count for Team Mgmt 01-31-2023.xlsx

Regex to use in the Regex Split Node: (.?)(\d{2}-\d{2}-\d{4})(.?)

Should result in this:

3 Likes

Thank you! @MartinDDDD this worked exactly how I was expecting. Do you mind share how the formula works, just for my general knowledge? thanks

You’re welcome.

First of all I recommend https://regex101.com/ to test regex expressions.

What does the expression do:

  • based on the structure of your path we expect three segments - before the date, the date, and after the date. That’s why the expression contains three subgroups ()()()
  • the first and the last group use (.?): . means any character and ? means match that any character as many times (until you hit the next group) - that means the first (.?) selects everything until the date and the second (.?) everything after the date
  • the middle group uses \d which matches any digit 0-9 followed by {2) which means, find any too consecutive digits. the “-” in-between means match a dash and at the end there’s another \d for digits with {4} to indicate 4 numbers are required.

Hope that makes sense.
regex101 explains this probably a bit better (in the top right corner marked in red square):

2 Likes

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