I'm trying to find all the characters that are required in the regex (it will never match without them). I would like all characters to be returned in a list. For example (a)+ would return ["a"] and c(b)+ would return ["c","b"]. However, [ab]+ would return [] because either character is matched, but both don't need to be.
I tried
def reg_chars(reg):
import re
chars = list( '!"#$%&\'()*,-./0123456+789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~')
for char in chars:
if re.match(reg,char):
return char
however it is very inefficient, can only match one character, and never works if there is anything like [ab]+ in the regex.