How to check whether a string contains special character in ruby. If I get regular expression also it is fine.
Please let me know
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.
You can then use the regex to test if a string contains the special character:
This looks a bit complicated: what’s going on in this bit
is to turn this
into this:
Which is every character in special, escaped with a
\(which itself is escaped in the string, ie\\not\). This is then used to build a regex like this: