Regular expression to identity special character

Hello friends i need a regular expression which will check if the string contain the special character or not? and accordingly it should return true, false value.

Thanks
abhi

Hello friends i need a regular expression which will check if the string
contain the special character or not? and accordingly it should return true,
false value.

Depends entirely on what you mean by special character?

Fred

Hey Fred,
Suppose i have a string “abcde fghi” it should gives true, and suppose if i have a string “abcd %$# fghi” it should return false.

Thanks

That’s still not very precise. Do you mean anything that’s not a letter or a space? What about punctuation, numbers etc… ? You’re probably just going to end up with one of the builtin character classes like \w or custom ones like [a-z]

yes basically i don’t want my string should contain any ‘punctuation’ if so then it should return false.
regards
abhishek

Hi Abhishek,

Take a look on this article:

http://marcricblog.blogspot.com/2008/08/bitwising-ruby.html

More specifically, the last example.

On that case I just consider words. You will need to adapt it to your
needs.

Regards.

You can use http://www.rubular.com/ to test and find the regex you
need.