- 1

Can anyone help me in java coad coach

import java.util.regex.Pattern; import java.util.regex.Matcher; import java.util.*; public class Joke { public static String extractYTId(String ytUrl) { String vId = null; Pattern pattern = Pattern.compile( "^https?://.*(?:youtu.be/|v/|u/\\w/|embed/|watch?v=)([^#&?]*).*

quot;, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(ytUrl); if (matcher.matches()){ vId = matcher.group(1); } return vId; } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); Joke obj = new Joke; obj.extractYTId(scan); }

18th Jul 2020, 8:17 PM
Pratik Shinde
Pratik Shinde - avatar
3 Antworten
+ 10
It'd be easier for people to help you if your attempt was linked via a code-playground URL.
21st Jul 2020, 4:23 PM
Fox
Fox - avatar
+ 3
I don't really know a lot of Java. I'm sure someone will get around to look at it.
18th Jul 2020, 9:39 PM
HonFu
HonFu - avatar
+ 2
Hello Pratik Shinde Your method is in same class like main method and it is static. So you don't need an instance of Joker. And the method returns a String: String link = extractYTId(scan); Now you can print this String to see if it works.
19th Jul 2020, 11:54 AM
Denise Roßberg
Denise Roßberg - avatar