Biks 9 Posted August 22, 2010 Report Share Posted August 22, 2010 I took a whole day to figure out how to trim, delete or replace stuff using a Javascript expression within Ubot, so I figured I might as well share it. I have had not one drop of javascript programming experience, so you hot shot programmers can shrug and scoff all you want. :-) I'll try to explain this from a complete noobs perspective. My objective: I wanted to trim down any long URL to the basic domain.Take something like this: http://www.ubotstudio.com/forum/index.phpTurn it into this: ubotstudio.com You should be able to use what I show with ANY type of text string. I created a running demo of the javascript strings to show you HOW they would be used within Ubot. Download: Shorten URL.ubot http://www.macrorecorder.org/images/strip-ui.png You'll enter a long URL into the UI box above, hit the play button and you'll see the results in the UI stat monitor below. The demo just shows the end result of the variable. You would use this updated variable within your own bots. Here's everything for pattern matching characters: javascriptkit.com/javatutors/re2.shtml --- Strip Front Tab ----- http://www.macrorecorder.org/images/strip-front.png The flow is:'LOOK AT ALL THIS JUNK' .replace /WHATEVER I FIND HERE/ , 'WITH THIS' ; As a non programer, I was having a hard time figuring out where things started and ended. (/( = is this something? How about this = /, ? The sections are: '{1}' = your variable will be inserted here. Just {1} won't work - you need '{1}'.replace( ); = This is the outside portion of the .replace expression./ / = this is an inside group, = find the stuff to the left of the comma and replace it with what's on the right( )|( ) = Alterations of groups - (THIS) O|R (THAT) In this instance we're looking either http:// or http://www'' = empty or nothing. Sometime you WILL have something like '{1}' (a variable) Notice that there are no slashes here: (http:..www.)|(http:..)This won't work: (http://www.)|(http://)Reason: using a / would mean the end of a section. You've got to use a . (dot). = match ANY single character --- Strip End Tab ----- http://www.macrorecorder.org/images/strip-back.png The flow is:'LOOK AT ALL THIS JUNK' .replace /STARTING FROM THE END AND GOING BACKWARDS, SELECT EVERYTHING AND INCLUDING .COM/ , 'WITH JUST .COM' ; In reverse order:$ = start at the end (^ = start at the beginning). = ANY single character+ = match one or more characters .+. = any character, to any AMOUNT of characters, to any character again. This is the closest you'll come to the standard wildcard (*). ----- Strip both ----- Notice that it strips #URL first and updates #strip, then it strips #strip and updates #URL. By ping pong between variables you can keep updating your original data. --- Other examples ---- Let's say you wanted just the authors name to a post. The narrowest scape you can do this: Harry Kabonzi | August 20, 2010 You would run this: '{1}'.replace(/ \x7c.+.$/, ''); The tricky part is the "|" symbol. This won't work: '{1}'.replace(/ |.+.$/, ''); You need to use the hex # for the "|" symbol, which is \x7c. In this case, I'm also adding a blank space before it so I end up with only "Harry Kabonzi". To find more hex #'s, go here. Again, check out this website for more pattern matching characters: javascriptkit.com/javatutors/re2.shtml 3 Quote Link to post Share on other sites
MiriamMB 63 Posted August 22, 2010 Report Share Posted August 22, 2010 Hey Biks, great job :-) Perhaps I should move this thread to "Tutorials, Tips and Tricks". Would that be alright with you? Quote Link to post Share on other sites
Biks 9 Posted August 23, 2010 Author Report Share Posted August 23, 2010 Certainly. I was gonna do that, then I noticed a bunch of things like that were moved to here! (Scripting) Quote Link to post Share on other sites
MiriamMB 63 Posted August 23, 2010 Report Share Posted August 23, 2010 Certainly. I was gonna do that, then I noticed a bunch of things like that were moved to here! (Scripting) I'll pin it then for future reference. Quote Link to post Share on other sites
Abs* 12 Posted October 27, 2010 Report Share Posted October 27, 2010 hi guys this is a great thread and very usefull im a little stuck and was wondering if someone could shed some light as to what im doing wrong Im trying to load a list of urls from a file then trim them to the route and save the list to another file - I have over 100 urls in the file however when i strip and save it only saves 1 url any help is appreciated - image attached below thanks abs Quote Link to post Share on other sites
JohnB 255 Posted October 27, 2010 Report Share Posted October 27, 2010 Did you place that in a loop to loop through the list? Your image shows an if/then statement, so I am unsure what lies above. John Quote Link to post Share on other sites
Abs* 12 Posted October 27, 2010 Report Share Posted October 27, 2010 hi no loop - the if statement is a evaluate if xx checkbox =true Quote Link to post Share on other sites
Biks 9 Posted October 28, 2010 Author Report Share Posted October 28, 2010 I'm pretty sure you've got to loop it. Load the first one from your list.Strip it.Save it to another list.Loop. (list total amount)Save to file. You've got to apply it one line at a time. You don't feed it a huge list and it change/replaces everything like in a text doc. Quote Link to post Share on other sites
Abs* 12 Posted October 29, 2010 Report Share Posted October 29, 2010 ahh bikes - it makes sense - So just loop list total > get next list item then strip - add to new list - save to file sounds like a plan thanks Quote Link to post Share on other sites
Super Dave 26 Posted February 11, 2011 Report Share Posted February 11, 2011 I'd like to recommend that anyone using anything dealing with javascript add this bug fix to their codes. If the page you're navigating to doesn't contain javascript ubot doesn't have any libraries to go off of either. This fixes that. Skip through the comments and feel free to copy the sub at the end.javascript-fix.ubot 1 Quote Link to post Share on other sites
bheeelaat 0 Posted June 19, 2011 Report Share Posted June 19, 2011 Nice Guide sir! Its verey usefeul especially for newbie like me Quote Link to post Share on other sites
ubotapp 0 Posted December 8, 2011 Report Share Posted December 8, 2011 Does this work in 4.0? I tried to copy the steps in the image, but I don't know how to enter this part into the eval statement so it shows up as a red node: '{1}'.replace(/.com.+$/,'.com'); where I can put a parameter inside the node. Quote Link to post Share on other sites
southsider 0 Posted March 14, 2012 Report Share Posted March 14, 2012 Does this work in 4.0? I tried to copy the steps in the image, but I don't know how to enter this part into the eval statement so it shows up as a red node: '{1}'.replace(/.com.+$/,'.com'); where I can put a parameter inside the node. For {1}, drag a drop a variable in between the ' ' Quote Link to post Share on other sites
soulpower 3 Posted June 6, 2012 Report Share Posted June 6, 2012 great info here...i really needed this. Thanx guys Quote Link to post Share on other sites
Security 17 Posted June 11, 2012 Report Share Posted June 11, 2012 Can you do the same things using Regex ? or is this way better or something ? Quote Link to post Share on other sites
inview 0 Posted September 27, 2012 Report Share Posted September 27, 2012 Great thread.I wish I could download stuff Just wondering - why would there be a restriction till I have 50?, seems strange? Quote Link to post Share on other sites
Aymen 385 Posted September 28, 2012 Report Share Posted September 28, 2012 Great thread.I wish I could download stuff Just wondering - why would there be a restriction till I have 50?, seems strange?if you got a ubot license , contact the support team to make them lift the limitation Quote Link to post Share on other sites
inview 0 Posted September 29, 2012 Report Share Posted September 29, 2012 if you got a ubot license , contact the support team to make them lift the limitation Thank you for sorting that Aymen, very much appreciated Quote Link to post Share on other sites
Automator 2 Posted July 30, 2013 Report Share Posted July 30, 2013 I'm late to the party, but thanks for this, guys! 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.