Jump to content
UBot Underground

Noobs guide to Javascript strings


Recommended Posts

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

Turn 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

  • Like 3
Link to post
Share on other sites
  • 2 months later...

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

post-785-12881961460553_thumb.gif

Link to post
Share on other sites

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.

Link to post
Share on other sites

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

Link to post
Share on other sites
  • 3 months later...
  • 4 months later...
  • 5 months later...

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.

Link to post
Share on other sites
  • 3 months later...

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

Link to post
Share on other sites
  • 2 months later...
  • 3 months later...

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

Link to post
Share on other sites
  • 10 months later...

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