An alternative method uses strsplit(), a regex short form for 'everything but letters' to split the vector on, and code to keep only the first part: the letters before the pipe (the negative 2).
var <- c("AF|2312", "BWDS|54", "JFD|2111")
var <- sapply(strsplit(var, split = "\W"), "[", -2)
var
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…