darvid / python-hyperscan

🐍 A CPython extension for the Hyperscan regular expression matching library.
https://python-hyperscan.readthedocs.io/en/latest/
MIT License
165 stars 28 forks source link

Add args for early termination of scanning if only need to find one match regex or just judging matched #118

Open betterlch opened 6 months ago

betterlch commented 6 months ago

Thanks for your excellent work!

And here is some using case to improve

I'm catching hyperscan.ScanTerminated to break scan if I return True and raise HS_SCAN_TERMINATED error in callback func match_event_handler. Which can early termination of scanning if I only want to know is matched but don't care whitch regex is mtached. It can be achieved by catching hyperscan.ScanTerminated or modify Database_scan in hyperscanmodule.c by judging HS_SCAN_TERMINATED and HS_SUCCESS.