Jump to content
UBot Underground

Removing Duplicates from List ReGex


Recommended Posts

Being new to uBot...EVERYTHING is a challenge! I'm sure the uBot "gurus" here on the forum don't have this problem...but I sure did.

 

I scraped a list of URLs from Google. There were lots of duplicates in my list so I wanted to use the $replace regular expression feature to clean my list. I found several regex's online, both for sorted and unsorted lists. Anyways, here is the code I used in uBot v4. It may not be pretty...but it works! I hope it will help some other poor newbie soul out. This regex deletes duplicates in lists that are either sorted or unsorted.

 

My code:

 

clear list(%dupesremoved)

add list to list(%dupesremoved, $list from file("C:\\GoogleURLs\\GoogleURLs.txt"), "Delete", "Global")

save to file("C:\\GoogleURLs\\DupesRemoved.txt", $replace regular expression(%dupesremoved, "^(.*)(?:\\r?\\n|\\r)(?=[\\s\\S]*^\\1$)", ""))

 

sales

Link to post
Share on other sites

I'm still trying to wrap my head around using simple regex in v.4... for example if I want to trim the white space from the left side or right side (or both) only of a variable what do I need to do to this code to make it work?

 

ui text box("Text to Trim", #test)

ui button("Trim Left") {

set(#test, $replace regular expression(#test, "/^\\s+/, \'\'", $nothing), "Global")

}

ui button("Trim Right") {

set(#test, $replace regular expression(#test, "/\\s+$/, \'\'", $nothing), "Global")

}

ui button("Trim All") {

set(#test, $replace regular expression(#test, "/^\\s+|\\s+$/g, \'\'", $nothing), "Global")

}

 

http://ubotstudio.com/forum/public/style_emoticons/default/blink.gif

Link to post
Share on other sites
I'm still trying to wrap my head around using simple regex in v.4... for example if I want to trim the white space from the left side or right side (or both) only of a variable what do I need to do to this code to make it work?

 

ui text box("Text to Trim", #test)

ui button("Trim Left") {

set(#test, $replace regular expression(#test, "/^\\s+/, \'\'", $nothing), "Global")

}

ui button("Trim Right") {

set(#test, $replace regular expression(#test, "/\\s+$/, \'\'", $nothing), "Global")

}

ui button("Trim All") {

set(#test, $replace regular expression(#test, "/^\\s+|\\s+$/g, \'\'", $nothing), "Global")

}

 

just use $trim

Link to post
Share on other sites

Actually, I'm trying to learn how to do it with regex because with $trim you can't specify between left and right trim and I'd like to know how to do this... as well as using regex in a set command for a hundred other regular expressions that aren't hotlisted... yet... http://ubotstudio.com/forum/public/style_emoticons/default/wink.gif

Link to post
Share on other sites

Actually, I'm trying to learn how to do it with regex because with $trim you can't specify between left and right trim and I'd like to know how to do this... as well as using regex in a set command for a hundred other regular expressions that aren't hotlisted... yet... http://ubotstudio.com/forum/public/style_emoticons/default/wink.gif

 

Here ya go, this should help:

 

set(#text, " the cow and the dog ", "Global")

set(#trimleft, $replace regular expression(#text, "^\\s+", ""), "Global")

set(#trimright, $replace regular expression(#text, "\\s+$", ""), "Global")

set(#trimboth, $replace regular expression(#text, "^\\s+|\\s+$", ""), "Global")

  • Like 1
Link to post
Share on other sites

There we go... awesome!!

 

I feel the wonderful world of regex opening up right before my eyes...

 

Thanks Bro!

 

http://ubotstudio.com/forum/public/style_emoticons/default/smile.gif

Link to post
Share on other sites

There we go... awesome!!

 

I feel the wonderful world of regex opening up right before my eyes...

 

Thanks Bro!

 

http://ubotstudio.com/forum/public/style_emoticons/default/smile.gif

 

np, if you don't have it, I highly recommend RegEX Buddy.

Great tool, I don't use it often, but for the tricky ones it is freaking awesome.

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