通过正则表达式匹配某个字符串之前的字符串,比如文件中包含字符串"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",如何通过正则表达式获取字符串"http://www.w3.org/", 即字符串"TR"之前的那一串
------解决方案--------------------------------------------------------
- Java code
System.out.println("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd".replaceAll("TR.*", ""));
------解决方案--------------------------------------------------------
不清楚 你需求
------解决方案--------------------------------------------------------
- Java code
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()); } }}
------解决方案--------------------------------------------------------
- Java code
import java. start=startTime.getDay();var fill=fillTime.getDay();if(start>=fill&&(startTime.getTime()-fillTime.getTime()<=(6-fill)*24*60*60*1000)){ alert("格式正确!");}