❔ How to get substring up until a certain pattern is seen?

I have a bunch of strings that look similar to: "TEST1_TEST_1995_12_324324_whatever" "test2_test_3_4_2001_test" What I am trying to do is get a substring up to but not including the underscore just before 4 digits in a row plus another underscore. In the above two examples, the first substring should give me "TEST1_TEST" because after that is the pattern underscore, four digits, underscore (1995). The second example should give me "test2_test_3_4" because the pattern after that is, again, underscore, four digits, underscore (2001). I've been messing around with regex but can't seem to get close.
8 Replies
Angius
Angius15mo ago
(.+)_\d{4} this should work, no?
Angius
Angius15mo ago
Angius
Angius15mo ago
https://regex101.com/r/4XN7Ic/1 Ah, no, doesn't work with the first one... (.+)_\d{4}_ this does, though
Angius
Angius15mo ago
Angius
Angius15mo ago
Or yeah, lazy I keep forgetting about it lol And just remember to always get the first capture
Nacho Man Randy Cabbage
damn was closer than I thought. thank you so much @visual studio core professional and @ZZZZZZZZZZZZZZZZZZZZZZZZZ !
Angius
Angius15mo ago
Ok
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server