2017-03-23 23 views

回答

1

嘗試此正則表達式:

v=([^\s&#]*) 

Demo

說明:

  1. v=字面上匹配V =
  2. ()捕獲基團,這種情況下組1,我想其值在到 這裏拍攝
  3. [^\s&#]*匹配所有內容,除非空格或&或#。 &是必要的,因爲 版本ID可能不是最後一個參數。 #是必要的,因爲#可用作URL中的書籤。

你可以試試:

final String regex = "v=([^\\s&#]*)"; 
    final String string = " https://m.youtube.com/watch?v=9tg3csrFVJw"; 
    final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 
    final Matcher matcher = pattern.matcher(string); 

    if(matcher.find()) { 
     System.out.println(matcher.group(1)); 
    } 

Run it here

相關問題