正则表达式:一个范围,但不包括几个项目?

时间:2016-12-12 08:59:23

标签: python regex vim

假设我想匹配一系列字符,一个玩具示例[0-9],但除了少数几个,比如说36

有几种方法可以解决这个问题:

  1. 列出他们
  2. a = 'a certain string'    
    the_range_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']   
    the_outliers_list = ['3', '6']    
    matched = re.search("[%s]" % "".join(list(set(the_range_list)-set(the_outliers_list))), a)
    
    1. 几个范围

      [0-24-57-9]

    2. 现有答案
    3. a = '23491782634798169'      
      r = '(?![36])[0-9]+'    
      re.findall(r, a)    
      

      我期望得到的是[" 2"," 491782",""," 47981"," 9"],但我得到的是[' 23491782634798169']。

      我的问题是,如果范围相当大,说所有CJK字符和异常是连续的(在Unicode表中)或离散列表,我如何使用正则表达式来表示这样的范围?在Vim或/和Python中的任何实现?

      希望这不会重复。

0 个答案:

没有答案