URL Parsen

downset04

Erfahrenes Mitglied
hallo

weiß jemand wie man am besten aus einer url den host parst?(ohne Bibliothek URL zu verwenden die das ja automatisch kann) ?

thx
 
Hallo!

Code:
  /**
   * 
   */
  package de.tutorials;
  
  import java.net.URL;
  
  /**
   * @author Tom
   *
   */
  public class HostFromURLExtractionExample {
  
  	/**
  	 * @param args
  	 */
  	public static void main(String[] args) throws Exception{
  		System.out.println(new URL("http://www.tutorials.de/forum36").getHost());
  	}
  
  }

Gruß Tom
 
ne darf so nid sein muss ohne import java.net.URL; sein muss mit regex sein
hab auf newsgroup sowas gefunden das soll aber nid 100%ig ? wie die sagen?
Code:
RE regexp;      
 REMatch[] regexpMatch;           
regexp = new RE ("http://|+?/|(.*/)|.+");      
 regexpMatch = regexp.getAllMatches(args[0]);
 
Hallo!

Code:
 /**
  * 
  */
 package de.tutorials;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
  * @author Tom
  *
  */
 public class HostFromURLExtractionExample {
 
 	/**
 	 * @param args
 	 */
 	public static void main(String[] args) throws Exception{
 		//In diesem Regex hab ich jetzt mal die Möglichkeit von Userkennungen  (foo:bar@www.tutorials...) vernachlässigt...
 		Matcher matcher = Pattern.compile("//([^:|/]*)?").matcher("http://www.tutorials.de:8080/forum36");
 		if(matcher.find()){
 			System.out.println(matcher.group(1));
 		}
 	}
 
 }

gruß Tom
 

Neue Beiträge

Zurück