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 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 - regular expression findall() in Python - Stack Overflow
regex - Python Regular Expression findall with variable - 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,']
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.
This solution should work:
me = re.findall(rf"(?<='(.+)'+{variable}+'(.+)')(.*?)(?='(.+)+{variable}+(.+)')", raw)
You also can add many different variables as you wish. Add rf for the regular expression and the desired variables in between {}
import re
text = "regex is the best"
var1 = "is the"
var2 = "best"
yes = re.findall(rf"regex {var1} {var2}", text)
print(yes)
['regex is the best']
I'm not sure if this is what you mean, but it may get you started. As far as I understand your question, you don't need lookaheads or lookbehinds. This is for Python 2.x (won't work with Python 3):
>>> import re
>>> string_to_search = 'fish, hook, swallowed, reeled, boat, fish'
>>> entered_by_user = 'fish'
>>> search_regex = r"{0}(.+){0}".format(entered_by_user)
>>> match = re.search(search_regex, string_to_search)
>>> if match:
... print "result:", match.group(1).strip(' ,')
...
result: hook, swallowed, reeled, boat
If you really want the last 'fish' in the result as in your comment above, then just remove the second {0} from the format() string.