❔ 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
Angius9mo ago
(.+)_\d{4} this should work, no?
Angius
Angius9mo ago
Angius
Angius9mo ago
https://regex101.com/r/4XN7Ic/1 Ah, no, doesn't work with the first one... (.+)_\d{4}_ this does, though
Angius
Angius9mo ago
Angius
Angius9mo 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
Angius9mo ago
Ok
Accord
Accord9mo 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
More Posts
❔ What is the Best Way to convert the nested C# object to key value pairI want to store the C# objects in MongoDB which can be dynamic nature in key value fashion like Attr❔ Blazor WebAsm (.NET6) Breakpoints No Longer WorkingI had them working a few months ago before I took a break from the project but now they simply don't❔ Representing a custom map using GeoJSON data instead of a map of the globe. Is it possible?I was wondering if it were possible to create a custom map not of the Earth and use GeoJSON to creat❔ RecyclableMemoryStreams and Sending a Byte ArrayI am utilizing `RecyclableMemoryStream` to pool my memory streams in my networking project, but the ❔ What is the purpose of `ModelBindingContext.Model`, `ModelName`, and `ModelBinderAttribute.Name`?The docs are very unclear about this. If I should set `ModelBindingContext.Result` to `ModelBindingR❔ System.Numerics.Vector<double> limited to 2 components with NativeAOT instead of 4Hi! Im using the mentioned Vector struct for double Vectors and have seen that using NativeAOT it on❔ SSH.Net library using in C# App questionHello all, it is no problem to connect to an ssh server and run commands and copy files to the remot❔ how do i use discord webhooks in a console app?title❔ MSSQL server is not connecting to server please help me.TITLE: Connect to Server ------------------------------ Cannot connect to DESKTOP-C2CJAPC. -------❔ 100 Day Coding ChallengeSo for something called the gold dofe I need to a skills section for 18 months which can essentially