denrich 4 Posted April 16, 2014 Report Share Posted April 16, 2014 Hey Ubotters, Seeking help for a regex that will delete the first and last item from a list. Thanks Quote Link to post Share on other sites
UBotBuddy 331 Posted April 16, 2014 Report Share Posted April 16, 2014 Depends on the List. Provide an example and I will try my script. Buddy Quote Link to post Share on other sites
Gogetta 263 Posted April 17, 2014 Report Share Posted April 17, 2014 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/>")) Quote Link to post Share on other sites
UBotBuddy 331 Posted April 17, 2014 Report Share Posted April 17, 2014 @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 Quote Link to post Share on other sites
denrich 4 Posted April 17, 2014 Author Report Share Posted April 17, 2014 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. Quote Link to post Share on other sites
denrich 4 Posted April 17, 2014 Author Report Share Posted April 17, 2014 @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. BuddyThanks 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. Quote Link to post Share on other sites
Gogetta 263 Posted April 17, 2014 Report Share Posted April 17, 2014 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/>")) Quote Link to post Share on other sites
Gogetta 263 Posted April 17, 2014 Report Share Posted April 17, 2014 @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. BuddyNice code. I just try to avoid using regex for somthing like this since I have seen them break with some special chrachters. Quote Link to post Share on other sites
denrich 4 Posted April 17, 2014 Author Report Share Posted April 17, 2014 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 1 Quote Link to post Share on other sites
denrich 4 Posted April 17, 2014 Author Report Share Posted April 17, 2014 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. Quote Link to post Share on other sites
UBotBuddy 331 Posted April 17, 2014 Report Share Posted April 17, 2014 You already have it. When you setup a variable with a $List Total just add a minus 1 after the node and the $subtract will magically appear. like this http://screencast.com/t/IbVlmjjjjHJ Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted April 17, 2014 Report Share Posted April 17, 2014 I wanted to join the party.....you can do this too save to file("{$special folder("Desktop")}\\test-list.txt", "ABCDF")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 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted April 17, 2014 Report Share Posted April 17, 2014 You can do this too and save memory... save to file("{$special folder("Desktop")}\\test-list.txt", "ABCDF")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"), ","), ",.*,"), ",")) Quote Link to post Share on other sites
denrich 4 Posted April 17, 2014 Author Report Share Posted April 17, 2014 Thanks Buddy and TC for the info Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.