Make function ignore Case-sensitivity of its input

I want make findfirst() function Case-insensitive. I want to extract texts after Filter word in webpages text. Some webpages contains it as FILTER and some as Filter. How to make them equivalent ?

while for other webpages that contains Filter it shows correct output

For detailed understanding visit Get index corresponding to some number in list of outputs - #14 by raman_kumar

Maybe use a regex to compare with?

findfirst(r"Filter|FILTER",txt)
1 Like

suppose if some webpage contains it as_filter_ or FILter then what should i do ?
I mean isn’t there way to make it case-insensitive. :crazy_face:

If you add i after the regex it becomes case-insensitive:

findfirst(r"filter"i, txt)

See the r"..." documentation.

2 Likes

You could do something like this or add an ‘i’ :smile:

using IterTools

cp=collect(partition("abc fli FiLteR nmb",6,1))

findfirst(p->all(t->t[1] ∈ t[2], zip(p,zip("filter","FILTER"))), cp)

function imatch(s, patt)
    cp=partition(s,length(patt),1)
    for i in eachindex(cp)
        all(t->t[1] ∈ t[2], zip(cp[i],zip(lowercase(patt),uppercase(patt)))) ? (return i) : continue
    end
end


s="abc fli FiLteR nmb"
patt="FiLtEr"
imatch(s,patt)
1 Like