Is any regular expression to detect a valid regular expression ?
Is any regular expression to detect a valid regular expression ?
Here is your solution:
Incredible,
check out a try..catch or everything your language provides.
Components:
Never if you are strictly speaking about regular expressions and it not including some regular expression implementations that are actually context free grammars.
In regex there is one limitation of regular expressions which makes it impossible to write a regex that matches all and only regexes. You cannot match implementations such as braces which are paired. Regexes use many such constructs, lets take [] as an example. Whenever there is an [ there must be a matching ]. Simple enough for a regex “[.*]”.
And what makes it impossible for regexes is nested. How you will write a regex which matches nested brackets? you cannot without an infinitely long regex. You can match any number of nested parens through brute force but you can’t ever match an arbitrarily long set of nested brackets.
This capability is often referred to as counting the depth of the nesting. In regex definition does not have the capability to count.