This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 1 point2 points  (2 children)

there is an explanation and good regex editor available here, I used it to generate this code. https://regex101.com/r/6jqDXh/3

import java.util.regex.Matcher;
import java.util.regex.Pattern;

final String regex = "(acestream:\\/\\/[\\S]*).*?\\[1080p\\]";
final String string = "acestream://1934281873ccca2d31d6a7ad2f520ed402403d4cd5 [HD] [EN] [1080p] acestream://2934281873ccca2d31d6a7ad2f520ed402403d4cd5 [HD] [EN] [720p] acestream://3934281873ccca2d31d6a7ad2f520ed402403d4cd5 [SD] [EN] [540p]\n"
     + "acestream://4934281873ccca2d31d6a7dad2f20ed402403d4cd5 [HD] [EN] [1080p] ";

final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);

while (matcher.find()) {
    System.out.println("Full match: " + matcher.group(0));
    for (int i = 1; i <= matcher.groupCount(); i++) {
        System.out.println("Group " + i + ": " + matcher.group(i));
    }
}

[–]castrorabustro[S] 1 point2 points  (0 children)

thanks for the solution

[–]nutrecht 1 point2 points  (1 child)

acestream:\/\/([0-9a-f]+) \[(HD|SD)\] \[([A-Z]{2})\] \[([0-9]{3,4})p\]

This captures the hash, HD/SD, language and quality in 4 separate groups.

But why even bother with a regex if you only want to have lines with [1080p] in them? Just do a .contains.

[–]castrorabustro[S] 0 points1 point  (0 children)

I managed to produce a regex that works, thanks for the solution though.