I have a string. How I can check if the string is a regular expression or contains regular expression or it is a normal string?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only reliable check you could do is if the
Stringis a syntactically correct regular expression:Note, however, that this will result in
trueeven for strings likeHello WorldandI'm not a regex, because technically they are valid regular expressions.The only cases where this will return
falseare strings that are not valid regular expressions, such as[unclosed character classor(unclosed groupor+.