1

I'm making a bot in node.js for Discordapp.com that will pull information from a steam profile's xml. It gets the profile links from user messages.

I'm having a hard time trying to figure out a way for my bot to pull the link from messages as they're not consistent.

Messages could look like:

http://steamcommunity.com/profiles/76562119803123205611 look at that guys

or

Take a look at this www.steamcommunity.com/id/someusername/

or

look at this steamcommunity.com/profiles/766119803232061 looks cool right?

The only thing consistent in each is "http://steamcommunity.com/" everything else is different. Could I receive some help on how I would pull only that entire link from each message and nothing else?

Acto Wolfy
  • 13
  • 2

1 Answers1

0

This is a great place for regular expressions. Here's one that will match any steamcommunity.com URL with /profiles/ followed by a number and /id/ followed by characters.

var test = "www.steamcommunity.com/id/someusername/";
var regexp = new RegExp("(steamcommunity.com)(/id/[a-z]+|(/profiles/(\d)+))", "i");
var out = test.match(regexp)[0];
Jack Guy
  • 8,346
  • 8
  • 55
  • 86