I already solved with if else and count, but I’m really what to know if you have some solution to check if a word has more than a character.
I want to check if any string given just have to be a, b or c. It will fail if it’s aaa, ab, cc, dd.
Like I said before I already have a solution but using if’s I would like to use regexp with ruby.
Thanks.
To match ‘a’, ‘b’ or ‘c’, but nothing else, you can use this regex:
To check if a string is empty or contains anything other than a single ‘a’, ‘b’ or ‘c’, this should do the trick:
Depending on what characters you want to allow, you may need to replace the
[abc]and[^abc]parts. For example, allowing the whole (lower-case) alphabet would require the following character classes:[a-z],[^a-z].