7 个解决方案
#1
System.out.println("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".replaceAll("TR.*", ""));
#2
谢谢1楼的回复,不过内容是变化的,只知道存在一个http://.../TR/xhtml11...这样的一个子串,如
ftp://www.w3.org/TR/xhtml1/DTD/,http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd,
http://www.w3.org/HR/xhtml1/DTD/
ftp://www.w3.org/TR/xhtml1/DTD/,http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd,
http://www.w3.org/HR/xhtml1/DTD/
#3
不清楚 你需求
#4
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String str = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
Pattern pattern = Pattern.compile("http://.*(?=TR/xhtml1.*)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
#5
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) throws ParseException {
Pattern p = Pattern.compile("(http://)?(([^/ ]+/)+)([^ ]+)");
Matcher m = p
.matcher("a/x.jpg http://server.php/b/x/123.jpg server/b/x/黄彪.x.jpg server/b/x/Yahoo.jpg");
while (m.find()) {
String protocol = m.group(1) == null ? "" : m.group(1);
System.out.println(protocol + m.group(2) + " => " + m.group(4));
}
p = Pattern.compile("(([^\\. ]+\\.)+)([^ ]+)");
m = p.matcher(":com.factory.web.Person :com.factory.web.Animal");
while (m.find()) {
System.out.println(m.group(1) + " => " + m.group(3));
}
// 这里是你需要的,前面的我懒得删除了,*^_^*
p = Pattern.compile("([^,]+)TR");
m = p.matcher("ftp://www.w3.org/TR/xhtml1/DTD/"
+ ",http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
+ ",http://www.w3.org/HR/xhtml1/DTD/");
while (m.find()) {
System.out.println(m.group(1));
}
}
}
#6
使用正则表达式的最小匹配、零宽断言
Pattern.compile("http://.*?(?=TR/xhtml1.*)");
Pattern.compile("http://.*?(?=TR/xhtml1.*)");
#7
先看看 看解决了没有啊
#1
System.out.println("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".replaceAll("TR.*", ""));
#2
谢谢1楼的回复,不过内容是变化的,只知道存在一个http://.../TR/xhtml11...这样的一个子串,如
ftp://www.w3.org/TR/xhtml1/DTD/,http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd,
http://www.w3.org/HR/xhtml1/DTD/
ftp://www.w3.org/TR/xhtml1/DTD/,http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd,
http://www.w3.org/HR/xhtml1/DTD/
#3
不清楚 你需求
#4
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String str = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
Pattern pattern = Pattern.compile("http://.*(?=TR/xhtml1.*)");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
#5
import java.text.ParseException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) throws ParseException {
Pattern p = Pattern.compile("(http://)?(([^/ ]+/)+)([^ ]+)");
Matcher m = p
.matcher("a/x.jpg http://server.php/b/x/123.jpg server/b/x/黄彪.x.jpg server/b/x/Yahoo.jpg");
while (m.find()) {
String protocol = m.group(1) == null ? "" : m.group(1);
System.out.println(protocol + m.group(2) + " => " + m.group(4));
}
p = Pattern.compile("(([^\\. ]+\\.)+)([^ ]+)");
m = p.matcher(":com.factory.web.Person :com.factory.web.Animal");
while (m.find()) {
System.out.println(m.group(1) + " => " + m.group(3));
}
// 这里是你需要的,前面的我懒得删除了,*^_^*
p = Pattern.compile("([^,]+)TR");
m = p.matcher("ftp://www.w3.org/TR/xhtml1/DTD/"
+ ",http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
+ ",http://www.w3.org/HR/xhtml1/DTD/");
while (m.find()) {
System.out.println(m.group(1));
}
}
}
#6
使用正则表达式的最小匹配、零宽断言
Pattern.compile("http://.*?(?=TR/xhtml1.*)");
Pattern.compile("http://.*?(?=TR/xhtml1.*)");
#7
先看看 看解决了没有啊