Jump to content
UBot Underground

Find All Occurrences Of Text String With Case Insensitive


Recommended Posts

I've tried looking around the forum to find the answer and can't seem to find the answer. So I hope someone can help me.

 

I have a simple list:

 

 

Kiwi

kiwi

Banana

Apple

cHerry

apple

APPLE

oranges

 

I want to use regex to find all occurrences of apple so it'll be like this (case insensitive):

Apple

apple

APPLE

 

More specifically I want to use an if command so that if this list contains apple (case insensitive). then A, else B.

 

Thank you

Link to post
Share on other sites

I think this is what you mean,has a list in it too

below this,I wrote a function a while ago for finding index's of list items(I don't think their is a Ubot function for this),mainly for local lists,wrote that below if it is of any use,never really used it myself,it is for case insensitive searching

 

set(#items,"Kiwi

kiwi
Banana
Apple
cHerry
apple
APPLE
oranges","Global")
clear list(%matches)
add list to list(%matches,$find regular expression(#items,"(?i)apple"),"Don\'t Delete","Global")
if($comparison($list total(%matches),">",0) {
    then {
        alert("greater")
    }
    else {
        alert("zero")
    }
}

 

 

=========================================================================

 

define $List Search(#list here#search query) {
    if($comparison(#list here,"=",$nothing) OR $comparison(#search query,"=",$nothing)) {
        then {
            return("-1")
        }
        else {
            add list to list(%myList,$list from text(#list here,$new line),"Don\'t Delete","Local")
            set(#position,0,"Local")
            loop($list total(%myList)) {
                if($comparison($change text casing($list item(%myList,#position),"Lower Case"),"=",$change text casing(#search query,"Lower Case"))) {
                    then {
                        add item to list(%result,#position,"Don\'t Delete","Local")
                        increment(#position)
                    }
                    else {
                        increment(#position)
                    }
                }
            }
        }
    }
    if($comparison($list total(%result),"=",0)) {
        then {
            return("-1")
        }
        else {
            return(%result)
        }
    }
    clear list(%myList)
}

 

add item to list(%re,"we","Don\'t Delete","Global")

add item to list(%re,"we","Don\'t Delete","Global")

set(#dsa,$List Search(%re, "WE"),"Global")
if($comparison(#dsa,"!=","-1")) {
    then {
        alert("greater")
    }
    else {
        alert("not found")
    }
}

  • Like 1
Link to post
Share on other sites
More specifically I want to use an if command so that if this list contains apple (case insensitive). then A, else B.

 

try

if($comparison($find regular expression(%myList,"(?i)apple"),"!= Does not equal","")) {
    then {
        alert("found")
    }
    else {
        alert("not found")
    }
}

 

  • Like 2
Link to post
Share on other sites

 

try

if($comparison($find regular expression(%myList,"(?i)apple"),"!= Does not equal","")) {
    then {
        alert("found")
    }
    else {
        alert("not found")
    }
}

Thanks so much for your help!

I think this is what you mean,has a list in it too

below this,I wrote a function a while ago for finding index's of list items(I don't think their is a Ubot function for this),mainly for local lists,wrote that below if it is of any use,never really used it myself,it is for case insensitive searching

 

set(#items,"Kiwi

kiwi

Banana

Apple

cHerry

apple

APPLE

oranges","Global")

clear list(%matches)

add list to list(%matches,$find regular expression(#items,"(?i)apple"),"Don\'t Delete","Global")

if($comparison($list total(%matches),">",0) {

    then {

        alert("greater")

    }

    else {

        alert("zero")

    }

}

 

 

=========================================================================

 

define $List Search(#list here#search query) {

    if($comparison(#list here,"=",$nothing) OR $comparison(#search query,"=",$nothing)) {

        then {

            return("-1")

        }

        else {

            add list to list(%myList,$list from text(#list here,$new line),"Don\'t Delete","Local")

            set(#position,0,"Local")

            loop($list total(%myList)) {

                if($comparison($change text casing($list item(%myList,#position),"Lower Case"),"=",$change text casing(#search query,"Lower Case"))) {

                    then {

                        add item to list(%result,#position,"Don\'t Delete","Local")

                        increment(#position)

                    }

                    else {

                        increment(#position)

                    }

                }

            }

        }

    }

    if($comparison($list total(%result),"=",0)) {

        then {

            return("-1")

        }

        else {

            return(%result)

        }

    }

    clear list(%myList)

}

 

add item to list(%re,"we","Don\'t Delete","Global")

add item to list(%re,"we","Don\'t Delete","Global")

set(#dsa,$List Search(%re, "WE"),"Global")

if($comparison(#dsa,"!=","-1")) {

    then {

        alert("greater")

    }

    else {

        alert("not found")

    }

}

THIS IS PERFECT! Exactly what I was looking for! Thank you :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...