Want to get exact match from sentence

Hi friends,

I need to search exact match from sentence .I want the expected
behavior should be like below by using ruby

=========================================================================
message = "The quick brown fox jumps over the lazy dog.”

Expected results :
searchdata = “brown fox” should match
searchdata = “brownfox” Donot match
if message like
message = "The quick @brown fox jumps. over the lazy dog.”
searchdata = “brown fox jumps” should match

if message like
message = "The quick @@brown fox jumps.# over the lazy dog.”
searchdata = “brown fox jumps” Doesnot match

Can anyone help

With the last example why should “brown fox jumps” not match “The
quick @@brown fox jumps.# over the lazy dog.”?

The substring “brown fox jumps” starts at position 12.

Peter H. wrote in post #1055132:

With the last example why should “brown fox jumps” not match “The
quick @@brown fox jumps.# over the lazy dog.”?

The substring “brown fox jumps” starts at position 12.

for my requirement i need to consider only single specialchar before and
after word

The you could use a.index(b) to find at what position b starts as a
substring of a and use that to look backwards two characters and check
them if they are acceptable.

def is_match(a, b)
pos = a.index(b)
if pos == nil
return false
elsif pos < 2
# we matched within the first 2 characters of the string
# there is not enough room for special charaters
return true
elsif a[pos-2,2] == ‘@@’
return false
else
return true
end
end

Warning! Untested code, just written in the email.