Regex in Python: Separate words from numbers JUST when not in list
问题 I have a list containing some substitutions which I need to keep. For instance, the substitution list: ['1st','2nd','10th','100th','1st nation','xlr8','5pin','h20'] . In general, strings containing alphanumeric characters need to split numbers and letters as follows: text= re.sub(r'(?<=\d)(?=[^\d\s])|(?<=[^\d\s])(?=\d)',' ',text,0,re.IGNORECASE) The previous regex pattern is separating successfully all numbers from characters by adding space between in the following: Original Regex ABC10 DEF