Hey guys, so imagine you have an array like this when reading your directory:
603-element Array{String,1}:
"PartFluidOut_0000.vtk"
"PartFluidOut_0001.vtk"
"PartFluidOut_0002.vtk"
"PartFluidOut_0003.vtk"
"PartFluidOut_0004.vtk"
"PartFluidOut_0005.vtk"
"PartFluidOut_0006.vtk"
"PartFluidOut_0007.vtk"
"PartFluidOut_0008.vtk"
"PartFluidOut_0009.vtk"
⋮
"PartFluid_0293.vtk"
"PartFluid_0294.vtk"
"PartFluid_0295.vtk"
"PartFluid_0296.vtk"
"PartFluid_0297.vtk"
"PartFluid_0298.vtk"
"PartFluid_0299.vtk"
"PartFluid_0300.vtk"
"_ResumeFluidOut.csv"
Then what I want to do is to filter in a way that I end up with the following result:
"PartFluidOut"
"PartFluid"
The way to this goal as I want it is:
- Only want to look at .vtk files, ie. everyother file type should be ignored
- Only want letters, so no numbers or underscores etc. in output
I’ve done it using this snippet of code currently:
filenames = readdir()
filterFiles = split.(filenames,"_")
k = []
for i = 1:length(filterFiles)
global k = push!(k,filterFiles[i][1])
end
deleteat!(k,length(k))
finalNames = unique(k)
println(finalNames)
This works, but is a bit hardcoded since I have to look for an underscore, and I would rather just remove all non-vtk files, then remove “.vtk” and then finally all numbers. I know that some might be able to do this efficiently with a regex function - as I am new to regex I would like to see such an example.
My question is not about optimizing my code, but improving the way it works/robustness, hopefully doing this with implementing some kind of regex.
Thanks for your time.