We have a bunch of file names of the form:
filename1(412)(4141567).csv, filename2(4214985).csv, filename3(34543).csv, filename4(3456984).csv, filename5(34582).csv, filename6(jrh)(234145).csv
What we are looking to do is truncate the file names so that we are left with only
filename1(412),filename2,filename3,...,filename6(jrh).
i.e. to cut off the end of the name up until the last "(" bracket.
We cannot use substring as each of the file names are not exactly the same length. Also the following code I found:
sub("(.*?)[(].*", "\\1", files)
does not work either as some file names have two sets of brackets.