It's still validating because it will only give you a string if the match succeeds. The fact that you can specify "I want the string which matches this part of the regex to go into this variable" is a feature provided by the regex library to make your code less verbose. It doesn't actually have anything to do with the regular expression itself, which is defined as either accepting or rejecting any input string.
The reason why a regular expression cannot be used to parse an irregular language like HTML is because for an expression to be regular, it must have an equivalent deterministic finite automaton, or DFA. The "finite" part of "finite automaton" means that any given DFA (and thus, any given implementation of a regular expression) can do its work and return its boolean answer using a bounded amount of memory.
Any functional HTML or XML parser will violate the pumping lemma because HTML and XML are defined recursively. These parsers have to use an amount of memory that is proportional to the size (or at least the nested depth) of the document. This requirement precludes the use of DFAs (and thus, regular expressions) to perform the parsing/validation. In other words, HTML, by requiring its opening tags to be matched with specific closing tags, requires recursive descent to parse correctly. Regular expressions cannot express recursion, so they can't be used to solve the problem of parsing or validating HTML.
View all comments
Show parent comment
1
u/nwL_ Sep 08 '17
Hm, in Java I use Regex to extract a string which matches the regex. No validation use for me there, just literally parsing and extracting.