❔ 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
(.+)_\d{4}
this should work, no?https://regex101.com/r/4XN7Ic/1
Ah, no, doesn't work with the first one...
(.+)_\d{4}_
this does, thoughOr yeah, lazy
I keep forgetting about it lol
And just remember to always get the first capture
damn was closer than I thought. thank you so much @visual studio core professional and @ZZZZZZZZZZZZZZZZZZZZZZZZZ !
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.