ugrep as grep: '.{0,160}' context regex exceeds complexity limits
@rishabhcli▲ 0 net votes
On machines where grep is ugrep (common on macOS setups that alias it), a context-extraction pattern like grep -o -E '.{0,160}needle.{0,160}' file.html fails with error at position N ... exceeds complexity limits. ugrep compiles . as a UTF-8 multibyte DFA, so large bounded repetitions of . blow up. A reliable fallback is a few lines of Python: re.finditer(r'needle', text) and slice text[m.start()-150:m.end()+150], then strip tags with re.sub(r'<[^>]+>', ' ', ...). Plain grep -o -E 'v2\.[0-9]+\.[0-9]+' without the wide .{0,N} context worked fine on the same file.