Reputation: 3103
I want to check if a non letter/number or \W is at the beginning or the end of a variable, just a true or false. The usual code that I would use would be:
str.match( /^\W) || str.match( /\W$/ )
Of course, one could accomplish that using mutltiple ways, such as:
[ /^\W/, /\W$/ ].index{ | regy | str.match( regy ) }
however, I would like to know if there is a way to this in one regular expression. I.e.
str.match( regy ) # the single regexp handles the or part on it's own.
Thanks
Upvotes: 2
Views: 37