Is it possible to detect a valid regular expression with another regular expression? If so please give example code below.
Good question.
True regular languages can not decide arbitrarily deeply nested well-formed parenthesis. If your alphabet contains '('
and ')'
the goal is to decide if a string of these has well-formed matching parenthesis. Since this is a necessary requirement for regular expressions the answer is no.
However, if you loosen the requirement and add recursion you can probably do it. The reason is that the recursion can act as a stack letting you "count" the current nesting depth by pushing onto this stack.
Russ Cox wrote "Regular Expression Matching Can Be Simple And Fast" which is a wonderful treatise on regex engine implementation.