Replace string using pattern to get thumbnail from youtube

0

I have the following string that comes from the content of a web page:

String entrada = "<!-- verVideo('nClycKgfetU','65660'); -->";

I want to transform this string using replaceAll (since there may be several) in:

String resultado = "http://img.youtube.com/vi/nClycKgfetU/0.jpg"

What I have so far:

x.replaceAll("<!-- verVideo\('", "http://img.youtube.com/vi/").replaceAll(",'65660'); -->", "/0.jpg");

The first replaceAll works fine, but the second will not work because the number 65660 is variable and random . I guess you have to replace it with some java pattern but I can not figure out what it is.

    
asked by Corpex 07.10.2017 в 23:04
source

1 answer

1

Well, after some time doing tests, I found the answer:

entrada.replaceAll("<!-- verVideo\('", "http://img.youtube.com/vi/").replaceAll("','\d+'\); -->", "/0.jpg");

The key was to add \d+ to take any number between the two quotes

    
answered by 07.10.2017 / 23:37
source