Regularexpression for check specialchars

Hi friends,
I want to check the string contains only specialchars or not
Can anyone help

Hi,

What do you mean by “specialchars”? You have to be more specific.

Try looking at character classes

[[:print:]]
[[:graph:]]

and their negations

[^[:print:]]
[^[:graph:]]

Brian C. wrote in post #1055059:

Try looking at character classes

[[:print:]]
[[:graph:]]

and their negations

[^[:print:]]
[^[:graph:]]

I mean anyspecialchars like !@#$%^&*()_+,./:
I have one variable for example

message = “hello”
Here message contains only characters

message="@#$%^"
In this case i have only specialchars I want to check the case like
these

If you only consider ASCII specialchars, you can simply enumerate them
in a character class:

/\A[!-/:-@[-`{-~]*\z/

This matches any string that is empty or consists only of the characters

!"#$%&'()*+,-./:;<=>?@[]^_`{|}~

However, since this regex is hard to read and requires knowledge of the
ASCII table, it’s probably better to use the POSIX classes mentioned by
Brian or property classes (\p{} syntax):

/\A[\p{ASCII}&&\p{Graph}&&\p{^Alnum}]*\z/

The “&&” means intersection and the “^” means negations. That is, you’re
selecting all ASCII characters which are visible (Graph property), but
not alphanumeric.

See Class: Regexp (Ruby 1.9.3) for explanations of
the syntax.