Suppose I want to match a range of characters, an example of a toy [0-9] , but with the exception of a few, say 3 and 6 .
There are several ways to solve this problem:
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)
multiple ranges
[0-24-57-9]
- existing answer
a = '23491782634798169' r = '(?![36])[0-9]+' re.findall(r, a)
What I expected to get is ["2", "491782", "," 47981 "," 9 "], but I get [23491782634798169].
My question is, if the range is quite large, then all the CJK characters and the exception are continuous (in the Unicode table) or a discrete list, how can I use regex to represent such a range? And any implementations for this in Vim and / or Python?
Hope this is not duplicated.
source share