To test a Stringon Regex, you can do any of five things:
1: use String#match:
' '.match /\s{1,}/
'f'.match /\s{1,}/
2: Use Regex#match:
/\s{1,}/.match ' '
/\s{1,}/.match 'f'
3: Use String#=~:
' ' =~ /\s{1,}/
'f' =~ /\s{1,}/
4: Use Regex#=~:
/\s{1,}/ =~ ' '
/\s{1,}/ =~ 'f'
5: Use Regex#===(this is what is used in statements case):
/\s{1,}/ === ' '
/\s{1,}/ === 'f'
Note: String#=== does not execute :
' ' === /\s{1,}/
'f' === /\s{1,}/
source
share