2

My last clip result is located here which gives me something like

Last clip created by HeyitsLonestar while playing Deadlight - https://clips.twitch.tv/SarcasticRacySrirachaTBCheesePull

I would like to be able to extract just the URL and put it in an iframe like below but have no clue how:

<iframe
src="https://clips.twitch.tv/embed?clip=SarcasticRacySrirachaTBCheesePull"
height="360"
width="640"
frameborder="0"
scrolling="no"
allowfullscreen="true">
</iframe> 

It seems I would need the last part of the URL to make this automated anytime a new clip is created:

 SarcasticRacySrirachaTBCheesePull
Ates Goral
  • 137,716
  • 26
  • 137
  • 190
samuel
  • 21
  • 2

2 Answers2

1

assuming your structure always starts with clips.twitch.tv/ you can use this regular expression to extract only the final content:

/^(.+\/(\w+))?/gm

If you want to check a example of this, you could look at this Codepen

João Deroldo
  • 465
  • 4
  • 9
  • 1
    The `g` (global) flag is redundant when you're just extracting one bit out of one string. The `m` (multi-line) flag doesn't apply to this problem because the OP's actual HTTP response seems to be all in one line even though the original question made it seems like multiple lines. – Ates Goral Oct 30 '18 at 16:41
1

If the format of the result is guaranteed to always end with the URL, you can split the string by / and grab the last token with:

result.split('/').pop()

While regular expressions are regularly used for string parsing, sometimes basic splitting just works and it's easier to follow.

Demo:

var result = 'Last clip created by HeyitsLonestar while playing Deadlight - https://clips.twitch.tv/SarcasticRacySrirachaTBCheesePull';

console.log(result.split('/').pop())
Ates Goral
  • 137,716
  • 26
  • 137
  • 190
  • What would the code be to check this page https://warp.world/scripts/latest-clip?access_token=05b7nxihtqyzhwjzamlrqz9ekpkliv and get that result of what you have above? The way you have it set up is just the result. Thank you this is helping. – samuel Oct 31 '18 at 18:24