How to check if inputted text in equal to word?

I am making a search system

Here’s the code:

local function Search()
    Search_Bar:GetPropertyChangedSignal("Text"):Connect(function()
        local search = string.lower(Search_Bar.Text)
        
        for i, v in	pairs(Scroll:GetChildren()) do
            if v:IsA("Frame") then
                if search ~= "" then
                    local item = string.lower(v.Name)
                    
                    if string.match(item, search) then
                        v.Visible = true
                    else
                        v.Visible = false
                    end
                else
                    v.Visible = true
                end
            end
        end
    end)
end

Search()

The search system works, but not the way I would like it to.

robloxapp-20220702-1321469

When I searched for Technology with the keyword te, Literature also appeared. This is because literature also contains te. What I want is when you type te only Technology should appear. (or any word that starts with te)

How do I achieve this? :thinking:

A simple fix would be to include ^ at the start of the match string so it only finds instances at the start of the word

if string.match(item, "^" .. search) then
3 Likes

the answer was perfectly said by embat you can learn more about string formatting here because you may need them later Formatting and Converting Strings (roblox.com) @abcanish123

2 Likes