I am new to regex, why does this not output 'present'?
tale = "It was the best of times, ... far like the present ... of comparison only. "
a = re.compile('p(resent)')
print a.findall(tale)
>>>>['resent']
From the Python documentation
If one or more groups are present in the pattern, return a list of groups
If you want it to just use the group for grouping, but not for capturing, use a non-capture group:
a = re.compile('p(?:resent)')
For this regular expression, there's no point in it, but for more complex regular expressions it can be appropriate, e.g.:
a = re.compile('p(?:resent|eople)')
will match either 'present' or 'people'.
(\d+)%.re.findall, yes. If no parentheses are found then the entire string will be the result element. When using search or match, you can specify the entire string by using result.group(0) or access the groups with result.group(1) etc.a = re.compile('(p(resent))')?
'resent'here. can you provide a better example of expected input/output?tale="resent present ppresent presentt"?