I've looked around but haven't been able to find a working solution to my problem.
I have an array of two strings input
and want to test which element of the array contains an exact substring Test
.
One thing I have tried (among numerous other attempts):
input = ["Test's string", "Test string"]
# Alternative input array that it needs to work on:
# ["Testing string", "some Test string"]
substring = "Test"
if (input[0].match(/\b#{substring}\b/))
puts "Test 0 "
# Do something...
elsif (input[1].match(/\b#{substring}\b/))
puts "Test 1"
# Do something different...
end
The desired result is a print of "Test 1"
. The input can be more complex but overall I am looking for a way to find an exact match of a substring in a longer string.
I feel like this should be a rather trivial regex but I haven't been able to come up with the correct pattern. Any help would be greatly appreciated!
input[1]
can contain more than just the single wordTest
input[1]
contains as long as you are looking for exact strings correspondenceinput[0]
string contains something similar toTest's
which will yield a false positive and send me into "Test 0"