def BEE_REGEX = ~/^[bB]\d+$/ final String beeName = ' b 7 7 7 '.replaceAll("\\s","") if (beeName ==~ BEE_REGEX) { print 'bob' }