findall only works with a string as input not a list.
You probably want to use map and re.match or re.search for example:
Also your regex has multiple repeat symbols in it and needs some tuning, this one seems to work J\w{3}son
import re
a = ["Jackson", "Johnson", "Jason"]
c = list(map(lambda x: re.search("J\w{3}son",x), a))
print([i.string for i in c if i])
output:
['Jackson', 'Johnson']
Update if your input type is just a string then your original expression was fine you just need to change the regex to the example above
import re
a = "Jackson Johnson Jason"
b = re.findall("J\w{3}son", a)
print(b)
output:
['Jackson', 'Johnson']
Answer from Alexander on Stack Overflowhow to re.findall
How to use Python regex pattern matching with re.findall(pattern, string)? - Stack Overflow
regex - How can I find all matches to a regular expression in Python? - Stack Overflow
Regex findall start() and end() ? Python - Stack Overflow
how to use re.findall so that it outputs from code = 'a, b, c' is ['a', 'b', 'c'] because a = re.findall([r'\D+,'], code) outputs ['a, b,']
Use re.finditer:
>>> import re
>>> sequence = 'aaabbbaaacccdddeeefff'
>>> query = 'aaa'
>>> r = re.compile(query)
>>> [[m.start(),m.end()] for m in r.finditer(sequence)]
[[0, 3], [6, 9]]
From the docs:
Return an
iteratoryieldingMatchObjectinstances over all non-overlapping matches for the RE pattern in string. The string is scanned left-to-right, and matches are returned in the order found.
You can't. findall is a convenience function that, as the docs say, returns "a list of strings". If you want a list of MatchObjects, you can't use findall.
However, you can use finditer. If you're just iterating over the matches for match in re.findall(…):, you can use for match in re.finditer(…) the same way—except you get MatchObject values instead of strings. If you actually need a list, just use matches = list(re.finditer(…)).
Your goal is to split a string into tokens by a separator, so a better way to do this than with re.findall() is with re.split(). In this case, you can use
>>> re.split(r"[,;.]\s", s)
['this', 'that', 'talk', 'love', 'hate', 'good', 'bad', 'all good.']
Unfortunately, this method either puts the period at the end of the last item if you use [,;.]\s as the regular expression, and adds an empty string at the end of the result list if you instead use [,;.]\s? as the regular expression. We can deal with this, however, by removing the last string:
>>> re.split(r"[,;.]\s?", s)[:-1]
['this', 'that', 'talk', 'love', 'hate', 'good', 'bad', 'all good']
You can use lookahead:
>>> list(re.findall(r"([a-z][a-z ]+(?=[,;.]))+", s))
['this', 'that', 'talk', 'love', 'hate', 'good', 'bad', 'all good']
But re.split() recommended by @murgatroid99 is better.