-1

For example:

array = ['text_first', 'text_second', 'text_third']

Now trying to compare with 'text_first_file', 'text_first_2023' or 'text11_first'

Trying to use regex - but failing.

UseCase:

array includes 'text_first_file' => TRUE
array includes 'text_first_2023' => TRUE
array includes 'text_first-2023' => TRUE
array includes 'text11_first'    => FALSE
Rubyist
  • 6,486
  • 10
  • 51
  • 86

1 Answers1

0

You don't need the regular expression

array = %w[text_first text_second text_third]
string = 'text_first_file'
p array.map { |x| string.include? x }.any?

Output

true
Rajagopalan
  • 5,465
  • 2
  • 11
  • 29