Ruby

Ruby

Made by DeepSource

Use start_with in place of regex RB-PR1021

Performance
Major

If a regex only checks if the string starts with a particular string, String#start_with? can be used as a simpler and more efficient method.

Bad practice

'abc'.match?(/\Aab/)
/\Aab/.match?('abc')
'abc' =~ /\Aab/
/\Aab/ =~ 'abc'
'abc'.match(/\Aab/)
/\Aab/.match('abc')

'abc'.match?(/^ab/)
/^ab/.match?('abc')
'abc' =~ /^ab/
/^ab/ =~ 'abc'
'abc'.match(/^ab/)
/^ab/.match('abc')

Recommended

'abc'.start_with?('ab')