Neighborhoods a regular expression

Category: Java SE
 
zsq778108
2013-08-20 05:51:07

Sponsored Links


as this string, and I now need to read www.google.com.hk% E6% A1% 8C% E9% 9D% A2% E8% B5% 84% E8% AE% AF
two strings

Sponsored Links

jiangganghua018
2013-08-20 06:04:34

String s="
Matcher m=Pattern.compile("http://(.*?)/.*?&q=(.*?)&.*").matcher(s);
if(m.matches()){
System.out.println("Host="+m.group(1));
System.out.println("q=   "+m.group(2));
}
cspokcs00
2013-08-20 06:07:13
do not have regular You can also ah.

package com.xuz.csdn.nov01;

public class NoRegex {

public static void main(String[] args) {
String s = "
String url = s.substring(0,s.lastIndexOf("/"));
System.out.println(url);
String[] array = s.split("&");
for (String string : array) {
if(string.startsWith("q=")){
System.out.println(string);
}
}
}

}
liuxudong980
2013-08-20 06:15:35

master
longwolf
2013-08-20 06:26:42
Thank you, on the first floor of the
If I need to get something similar to this in
how do
on top of this test is not passed
dede2215
2013-08-20 06:40:13

Thank
but the words such as ; can not get a

www.svn8.com this because I just need to get URL in demand in this period
liun99999
2013-08-20 06:57:06
You are right to do a generic? matter what kind of URL can be analyzed?
do a generic regular expression looks like a little more difficult, ah, because the characteristics of each URL is not the same

We do not have a regular expression, you can use this idea to achieve:
1) Host extraction well, do not say
2) to find the URL of Chinese argument, which is a percent of the parameters, If not found, then find the longest parameter

this result does not guarantee 100% accurate, but perhaps enough
pas_dts
2013-08-20 07:08:08
If
has a very rigid way
first interception interception www.svn8.com/dotnet/Csharp/2010012118412.html
longer feel this is too cumbersome www.svn8.com
That is mainly behind the
obtain similar% D7% C0% C3% E6% D7% CA% D1% B6 string looks like this is not easy getting a
xz381217835
2013-08-20 07:23:08

mainly want to be very convenient for access to those two things
just extract the host's canonical how to write it, under the wing of trouble thank
skynetok
2013-08-20 07:28:49


tang8811
2013-08-20 07:37:32
extract only Host:

//String s="";
String s="
Matcher m=Pattern.compile("http://([^/]*).*").matcher(s);
if(m.matches()){
System.out.println("Host="+m.group(1));
}
xu_feng_21
2013-08-20 07:48:33
personally feel, LZ think that way actually quite dull Well, not superstition regular expressions, huh
jiali117
2013-08-20 08:00:08
Thank you
knot posted
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.