you can use Regular Expressions (regex), but I'm not as skilled as I would like to be.
Alternatively you can use the following
Alternatively you can use the following
line = "Group1 ABC_YJK_02_S_2019-08-01 2" beginning, end = line.find('_'), line.find('_S_') result = line[beginning+1 : end] print(result)or
table = [ "Group1 ABC_YJK_02_S_2019-08-01 2", " ABC_YMK_5_S_2019-08-01 5", " ABC_JKL_S_2019-08-04 10", "Group2 BCA_POL_S_2019-08-01 4", " BCA_PAL_S_2019-08-01 5", " BCA_TYP_S_2019-08-01 50", " BCA_DIST_S_2019-08-01 23", " BCA_STA_S_2019-08-01 3"] n = len(table) resultsTable = [] for i in range(n): beginning, end = table[i].find('_'), table[i].find('_S_') result = table[i][beginning+1 : end] resultsTable.append(result)Paul