# How can I know if a pattern corresponds to a string pattern?

What would be the best way to detect if a pattern corresponds to a string pattern ? An invalid string pattern p would lead to an error in StringMatchQ[string, p] for example.

-
Have a look at SystemDumpvalidStringExpressionQ[]. –  Ｊ. Ｍ. Nov 20 '12 at 9:46
Yes that's the kind of built-in function I was looking for thanks. Maybe you could put the comment as an answer. –  Faysal Aberkane Nov 20 '12 at 9:51

At Faysal's behest: there's the (undocumented) function SystemDumpvalidStringExpressionQ[]:

SystemDumpvalidStringExpressionQ["**"]
True

SystemDumpvalidStringExpressionQ[_ ~~ 1]
False

-
A look at ??SystemDumpvalidStringExpressionQ is particularly enlightening... –  Ｊ. Ｍ. Nov 20 '12 at 10:01
Indeed so basically the pattern is passed to StringMatchQ in the general case and the function checks that no error occured. –  Faysal Aberkane Nov 20 '12 at 10:31
+1. A look at the implementation reveals some unpleasant behavior,e.g. stpatt = "**"; SystemDumpvalidStringExpressionQ[stpatt] returns False, while SystemDumpvalidStringExpressionQ[Evaluate[stpatt]] returns True. I would prefer to get True in both cases. –  Leonid Shifrin Nov 20 '12 at 10:33
StringPatternQ[_String | _StringExpression | _RegularExpression] = True;