In a string, I need to find the terms which contain missing opening brackets e.g. hi], hi}, hi)
I am able to find terms with a missing closing bracket in a string as shown below:
import re
missing_close = re.compile(r'(\w+|\s)?(\(|\[|\{)(\w+|\s)?[^\]})](\\|\s|\.)')
sen = "It is (fine [day]"
res_close = missing_close.finditer(sen)
for i in res_close:
print(i.group(0))
Output:
(fine
When a similar regex to find missing opening brackets,
missing_open = re.compile(r'(\\|\s|\.|\,)?[^\([{](\w+|\s)?(\)|\}|\])(\s|\.|\\)?')
sen = "It is} [fine] day"
res_open = missing_open.finditer(sen)
for i in res_open:
print(i.group(0))
Getting output with all terms having brackets
Output:
is}
fine]
Only is} is the needed output