Jump to content
UBot Underground

Regex to Delete First and Last Item from File


Recommended Posts

You don't need regex to do this. Use the remove from list command.

 

Here is an example:

clear list(%my list)
add list to list(%my list, $list from text("1
2
3
4
5
6
7
8
9
10", $new line), "Delete", "Global")
remove from list(%my list, 0)
remove from list(%my list, $subtract($list total(%my list), 1))
load html($replace($text from list(%my list, $new line), $new line, "<br/>"))

Link to post
Share on other sites

@Gogetta

 

Yeah that's good BUT check out this short code

add list to list(%junk, $list from text("Eddie
UBotBuddy
Gogetta", "
"), "Delete", "Global")
set(#var, $replace regular expression($replace(%junk, "
", "+"), "^.\{1,\}\\+(.\{1,\})\\+.\{1,\}", "$1"), "Global")
clear list(%junk)

Ahhhh

 

Reminds me of the good ole days when JohnB and I did this back and forth.

 

Buddy

Link to post
Share on other sites

 

You don't need regex to do this. Use the remove from list command.

 

Here is an example:

clear list(%my list)
add list to list(%my list, $list from text("1
2
3
4
5
6
7
8
9
10", $new line), "Delete", "Global")
remove from list(%my list, 0)
remove from list(%my list, $subtract($list total(%my list), 1))
load html($replace($text from list(%my list, $new line), $new line, "<br/>"))

Thanks for the help Gogetta. This one works well but not for a '$list from file' function it seems gets rid of the first but not the last item from the files list.

Link to post
Share on other sites

@Gogetta

 

Yeah that's good BUT check out this short code

add list to list(%junk, $list from text("Eddie
UBotBuddy
Gogetta", "
"), "Delete", "Global")
set(#var, $replace regular expression($replace(%junk, "
", "+"), "^.\{1,\}\\+(.\{1,\})\\+.\{1,\}", "$1"), "Global")
clear list(%junk)

Ahhhh

 

Reminds me of the good ole days when JohnB and I did this back and forth.

 

Buddy

Thanks Buddy, I should've been more specific, I am using the '$list from file' function maybe that s why it doesn't do the job.

Link to post
Share on other sites

Thanks for the help Gogetta. This one works well but not for a '$list from file' function it seems gets rid of the first but not the last item from the files list.

 

The code would work either way. Maybe your file has a blank line at the bottom. If this is the case then change the 1 to a 2 in the code below.

 

remove from list(%my list, $subtract($list total(%my list), 2))

 

Edit: Better yet here this should work with a balnk line left in th file or not.

clear list(%my list)
add list to list(%my list, $list from text("1
2
3
4
5
6
7
8
9
10
", $new line), "Delete", "Global")
remove from list(%my list, 0)
if($comparison($list item(%my list, $subtract($list total(%my list), 1)), "=", $nothing)) {
    then {
        remove from list(%my list, $subtract($list total(%my list), 2))
    }
    else {
        remove from list(%my list, $subtract($list total(%my list), 1))
    }
}
load html($replace($text from list(%my list, $new line), $new line, "<br/>"))

Link to post
Share on other sites

@Gogetta

 

Yeah that's good BUT check out this short code

add list to list(%junk, $list from text("Eddie
UBotBuddy
Gogetta", "
"), "Delete", "Global")
set(#var, $replace regular expression($replace(%junk, "
", "+"), "^.\{1,\}\\+(.\{1,\})\\+.\{1,\}", "$1"), "Global")
clear list(%junk)

Ahhhh

 

Reminds me of the good ole days when JohnB and I did this back and forth.

 

Buddy

Nice code. I just try to avoid using regex for somthing like this since I have seen them break with some special chrachters.

Link to post
Share on other sites

 

The code would work either way. Maybe your file has a blank line at the bottom. If this is the case then change the 1 to a 2 in the code below.

 

remove from list(%my list, $subtract($list total(%my list), 2))

 

Edit: Better yet here this should work with a balnk line left in th file or not.

clear list(%my list)
add list to list(%my list, $list from text("1
2
3
4
5
6
7
8
9
10
", $new line), "Delete", "Global")
remove from list(%my list, 0)
if($comparison($list item(%my list, $subtract($list total(%my list), 1)), "=", $nothing)) {
    then {
        remove from list(%my list, $subtract($list total(%my list), 2))
    }
    else {
        remove from list(%my list, $subtract($list total(%my list), 1))
    }
}
load html($replace($text from list(%my list, $new line), $new line, "<br/>"))

Yes you were right it was an extra empty line at the end..Thanks a lot, very appreciated :)

  • Like 1
Link to post
Share on other sites

 

 

The code would work either way. Maybe your file has a blank line at the bottom. If this is the case then change the 1 to a 2 in the code below.

 

remove from list(%my list, $subtract($list total(%my list), 2))

 

Edit: Better yet here this should work with a balnk line left in th file or not.

clear list(%my list)
add list to list(%my list, $list from text("1
2
3
4
5
6
7
8
9
10
", $new line), "Delete", "Global")
remove from list(%my list, 0)
if($comparison($list item(%my list, $subtract($list total(%my list), 1)), "=", $nothing)) {
    then {
        remove from list(%my list, $subtract($list total(%my list), 2))
    }
    else {
        remove from list(%my list, $subtract($list total(%my list), 1))
    }
}
load html($replace($text from list(%my list, $new line), $new line, "<br/>"))

Yes you were right it was an extra empty line at the end..Thanks a lot, very appreciated :)

 

One more thing, I only got the '$substract lists' Function from my tool box. Any way I can get the'$Substract' Function? Thanks.

Link to post
Share on other sites

I wanted to join the party.....you can do this too

 

save to file("{$special folder("Desktop")}\\test-list.txt""A
B
C
D
F")
clear list(%list)
add list to list(%list$list from text($find regular expression($text from list($list from file("{$special folder("Desktop")}\\test-list.txt"), ","), ",.*,"), ","), "Delete""Global")

 

TC

Link to post
Share on other sites

You can do this too and save memory...

 

 

save to file("{$special folder("Desktop")}\\test-list.txt""A
B
C
D
F")
save to file("{$special folder("Desktop")}\\test-list-2.txt"$list from text($find regular expression($text from list($list from file("{$special folder("Desktop")}\\test-list.txt"), ","), ",.*,"), ","))

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