java - Replacing regex group results - is it possible? -


i want validate html link, plus @ same time extract "http/https", host , address part. possible change group 1 value, let's if "https" - output "true" value:

string url = "https://www.youtube.com/watch?v=1m9tjpltcw8   ";  pattern p = pattern.compile("^(?i)(https?)://(.{3,}?)/(.*?) *$");//(?i) - case insensitive matcher m = p.matcher(url); if (m.find()) {     system.out.println("g1: " + m.group(1));     system.out.println("g2: " + m.group(2));     system.out.println("g3: " + m.group(3)); } 

the output is:

g1: https//but want replace - when "http" - "false", "https" - "true" g2: www.youtube.com g3: watch?v=1m9tjpltcw8 

what about

g1 = "http".equals(m.group(1)) ? "false" : "true" 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

gradle error "Cannot convert the provided notation to a File or URI" -