None of these examples are for parsing English sentences. They parse completely different formal languages. That it’s text is irrelevant, regex usually operates on text.
You cannot write a regex to give you for example “the subject of an English sentence”, just as you can’t write a regex to give you “the contents of a complete div tag”, because neither of those are regular languages (HTML is context-free, not sure about English, my guess is it would be considered recursively enumerable).
You can’t even write a regex to just consume <div> repeated exactly n times followed by </div> repeated exactly n times, because that is already a context-free language instead of a regular language, in fact it is the classic example for a minimal context-free language that Wikipedia also uses.
None of these examples are for parsing English sentences. They parse completely different formal languages. That it’s text is irrelevant, regex usually operates on text.
You cannot write a regex to give you for example “the subject of an English sentence”, just as you can’t write a regex to give you “the contents of a complete div tag”, because neither of those are regular languages (HTML is context-free, not sure about English, my guess is it would be considered recursively enumerable).
You can’t even write a regex to just consume
<div>
repeated exactly n times followed by</div>
repeated exactly n times, because that is already a context-free language instead of a regular language, in fact it is the classic example for a minimal context-free language that Wikipedia also uses.Read it again:
“At one point while working on the manuscript for this book. I ran such a tool on what I’d written so far”
The author explicitly stated that he used regex to parse his own book for errors! The example was using regex to parse html.
Just because regex can’t do everything in all cases doesn’t mean it isn’t useful to parse some html and English text.
It’s like screaming, “You can’t build an Operating system with C because it doesn’t solve the halting problem!”