Jump to content
UBot Underground

searching a list for regex


Recommended Posts

Once again, I really fail to see what i am doing wrong, why doesnt this work?

 

 

if($contains($list item(%forum_names_demo1, $list position(%forum_names_demo1)), $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"))) {

 

Do tell, i have fed in a list that contains data not matching the regex, yet ubot processes the THEN statement assuming that IF is matched

Link to post
Share on other sites

you are not looping through the list for one... Try this:

 

loop($list total(%forum_names_demo1)) {

if($contains($next list item(%forum_names_demo1), $find regular expression($next list item(%forum_names_demo1), "[nN]ame|[Ll]ocation|[Cc]ity"))) {

then {

}

else {

}

}

}

 

 

John

Link to post
Share on other sites

Ummmm actually I have done that, i just never copied the code, i have copied a bit more, see if you can catch what im doing wrong here

 

clear list(%forum_names_demo1)
clear list(%forum_names_demo2)
set(#forums_test_variable, "", "Global")
add list to list(%forum_names_demo1, $list from file("D:\\forums\\demo.txt"), "Delete", "Global")
add list to list(%forum_names_demo2, $list from file("D:\\forums\\demo1.txt"), "Delete", "Global")

loop($list total(%forum_names_demo1)) {
   wait(1)
   if($contains($list item(%forum_names_demo1, $list position(%forum_names_demo1)), $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"))) {
       then {
           set(#forums_test_variable, $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"), "Global")
           save to file("D:\\forums\\bath.txt", #forums_test_variable)

 

 

this is not the whole code tho'

Link to post
Share on other sites

If you were to add a stat monitor you would see you are not looping through the list. Use next list item, or this method:

 

ui stat monitor("Position", #position)

clear list(%forum_names_demo1)

clear list(%forum_names_demo2)

set(#forums_test_variable, "", "Global")

add list to list(%forum_names_demo1, $list from file("C:\\Users\\John\\Documents\\proclist.txt"), "Delete", "Global")

add list to list(%forum_names_demo2, $list from file("D:\\forums\\demo1.txt"), "Delete", "Global")

set(#position, 0, "Global")

loop($list total(%forum_names_demo1)) {

if($contains($list item(%forum_names_demo1, #position), $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"))) {

then {

set(#forums_test_variable, $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"), "Global")

save to file("D:\\forums\\bath.txt", #forums_test_variable)

}

}

increment(#position)

}

 

 

 

John

Link to post
Share on other sites

like i said that wasnt the WHOLE code, now i have copied the WHOLE code, let me know what is wrong (also i have just one item in my list, so i dont see what the prob is) and why do i have to set the list position as 0 initially, if all lists are cleared it should start automatically from 0.

 

 

 

clear list(%forum_names_demo1)

clear list(%forum_names_demo2)

set(#forums_test_variable, "", "Global")

add list to list(%forum_names_demo1, $list from file("D:\\forums\\demo.txt"), "Delete", "Global")

add list to list(%forum_names_demo2, $list from file("D:\\forums\\demo1.txt"), "Delete", "Global")

if($contains($list item(%forum_names_demo1, 0), "name")) {

then {

alert("POP")

}

}

loop($list total(%forum_names_demo1)) {

wait(1)

if($contains($list item(%forum_names_demo1, $list position(%forum_names_demo1)), $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"))) {

then {

set(#forums_test_variable, $find regular expression($list item(%forum_names_demo1, $list position(%forum_names_demo1)), "[nN]ame|[Ll]ocation|[Cc]ity"), "Global")

save to file("D:\\forums\\bath.txt", #forums_test_variable)

if($either($comparison($change text casing(#forums_test_variable, "Lower Case"), "=", "name"), $comparison($change text casing(#forums_test_variable, "Lower Case"), "=", "first name"))) {

then {

change attribute(<id="{$list item(%forum_names_demo2, $list position(%forum_names_demo1))}">, "value", #forums_fn)

}

}

if($either($comparison($change text casing(#forums_test_variable, "Lower Case"), "=", "city"), $comparison($change text casing(#forums_test_variable, "Lower Case"), "=", "location"))) {

then {

change attribute(<id="{$list item(%forum_names_demo2, $list position(%forum_names_demo1))}">, "value", #forums_city)

}

}

}

else {

change attribute(<id="{$list item(%forum_names_demo2, $list position(%forum_names_demo1))}">, "value", $prompt($list item(%forum_names_demo1, $list position(%forum_names_demo1))))

}

}

set list position(%forum_names_demo1, $add($list position(%forum_names_demo1), 1))

set list position(%forum_names_demo2, $add($list position(%forum_names_demo2), 1))

}

Link to post
Share on other sites

Because a loop is not going to iterate through a list of items unless you explicitly tell it to. Yes clearing the list resets the position, but without coding instructions to move through each list item, it will just stay on the first list item for as many cycles as you have instructed it to. In my example I set the variable for the list position so I can increment it. That tells it to go to the next item, and then the next, etc...you can also use next list item. What you cannot do is what you did in the code you gave me. Again, put up a stat monitor to monitor the list position, and you will see yours stays on 0.

 

 

John

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...