I'm trying to write a Python function using the re library, essentially trying to extract the word that is within the brackets. These words contain letters, and some words contain a plus sign or minus sign (but not all). This is the function I have so far:
def processArray(array):
newArray = []
for i in array:
m = re.search(r"\[([A-Za-z0-9\-\+]+)\]", i).groups()[0]
newArray.append(m)
return newArray
The array parameter passed in is [['Preconditions [+Here]\n'], ['Preconditions [+Is', '+The]\n'], ['Preconditions [-Example]\n']]. The newArray I hope to obtain is ['+Here', '-Is', '+The', '-Example']. With my current function, this is the error thrown out:
File "file.py", line 71, in <module>
preconditions = processArray(preconditions)
File "file.py", line 29, in processArray
m = re.search(r"\[([A-Za-z0-9\-\+]+)\]", i).groups()[0]
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/re.py", line 183, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
Could anyone explain why this error is occurring and what I can do to fix it?