I want to return trueif the line starts with a consonant. I have two conditions and I donβt know how to combine them.
true
1) this letter 2) it is not a vowel
!!(s[0] =~ /([a-z]&&[^aeiou])/i)
I tried all sorts of other syntaxes like:
!!(s[0] =~ /([a-z])([^aeiou])/i) !!(s[0] =~ /(([a-z])([^aeiou]))/i)
Is there a way to do this in one regex? Do I need to check each condition separately?
You can combine character classes with the operator &&:
&&
/[a-z&&[^aeiou]]/
Note that the operator is &&used inside the character class, not later.
In the documentation:
. isnt , [a-z[0-9]] , [a-z0-9]. &&, . :/[a-w&&[^c-g]z]/ # ([a-w] AND ([^c-g] OR z)) # This is equivalent to: /[abh-w]/
. isnt , [a-z[0-9]] , [a-z0-9]. &&, . :
[a-z[0-9]]
[a-z0-9]
/[a-w&&[^c-g]z]/ # ([a-w] AND ([^c-g] OR z)) # This is equivalent to: /[abh-w]/
, , .
\A(?=[^aeiou])(?=[a-z])
.
(?i:(?![aeiou])[a-z]\w*)
/^[bcdfghjklmnpqrstvwxyz]/i
, fancier.