tech_human
tech_human

Reputation: 7104

Matching string characters in regex

How do we represent a string in ruby like for integer we do \d, is it \s in ruby?

I tried \s and \c*, but nothing worked for me. I have a constraint in my file as per below:

constraints: {:name => /\s+/}

but its not accepting \s for some reason. For integer I use constraints: {:id => /\d+/} and it works.

Upvotes: 1

Views: 92

Answers (1)

Plasmarob
Plasmarob

Reputation: 1391

For word characters you would use:

constraints: {:name => /\w+/}

\s is whitespace, so it wouldn't mark words.

you could also use:

constraints: {:name => /\S+/}

This will check for any NON-whitespace chars.

It depends on what exactly you're wanting to match.

http://rubular.com/ (contains a list with its practice box)

Upvotes: 1

Related Questions