首页 > 技术文章 > Java regex non-capturing group "?:"

wade-case 2013-10-22 01:53 原文

  1. see: http://stackoverflow.com/questions/3512471/non-capturing-group
  2. usage: 
    (?:http|ftp)://([^/\r\n]+)(/[^\r\n]*)?
  3. Match "http://stackoverflow.com/"
         Group 1: "stackoverflow.com"
         Group 2: "/"
    
    Match "http://stackoverflow.com/questions/tagged/regex"
         Group 1: "stackoverflow.com"
         Group 2: "/questions/tagged/regex"

推荐阅读