script

script

Get complete substrings from a string

Hi
I have this html string

     "<div class=wp-block-supertrends-figure><div style=overflow: hidden; padding-top: 
      56.25%; position: relative;><iframe src=https://player.vimeo.com/video/687889699 
      frameborder=0 allowfullscreen=></iframe></div><div class=title>Video</div><div 
      class=text>Video description</div></div>" 

I need to extract https://player.vimeo.com/video/687889699 from it.
I need a Regex that matches on http as a starting character and get the entire url because there can be more links with different urls so I don’t want to hardcode this particular url and Regex is not my strong suit and I want to do it with Regex instead of using multiple String.split.
Any help would be appreciated.
Thank you.

Marked As Solved

fuelen

fuelen

iex> Regex.scan(~r/src=(\S+)/, string <> string, capture: :all_but_first)
[
  ["https://player.vimeo.com/video/687889699"],
  ["https://player.vimeo.com/video/687889699"]
]

Also Liked

mindok

mindok

A well-structured HTML parser, for example: GitHub - philss/floki: Floki is a simple HTML parser that enables search for nodes using CSS selectors. · GitHub, may be a more reliable option.

stefanluptak

stefanluptak

Naive approach:

str = """
<div class=wp-block-supertrends-figure><div style=overflow: hidden; padding-top: 
56.25%; position: relative;><iframe src=https://player.vimeo.com/video/687889699 
frameborder=0 allowfullscreen=></iframe></div><div class=title>Video</div><div 
class=text>Video description</div></div>
"""

Regex.run(~R|https://player.vimeo.com/video/[0-9]+|, str)
# ["https://player.vimeo.com/video/687889699"]

EDIT: Sorry, I just realized, there can be more URL formats. So consider this irrelevant.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

We're in Beta

About us Mission Statement