日期:2014-05-20  浏览次数:20630 次

用正则表达式截取字符串
我想用正则表达式截取字符串,就是一个网址,例如截取http://www.baidu.com,开头是以http://或者https://,结尾以空格活汉字结束,截取这中间部分,小弟不才,望各路大侠出手帮忙,不胜感激

------解决方案--------------------
Java code

        String ul = "123http://www.baidu.com测试 456";
        String regex = "(?<=https?://).+?(?= |[\\u4e00-\\u9fa5])";
        
        Matcher matcher = Pattern.compile(regex).matcher(ul);
        while(matcher.find()){
            System.out.println(matcher.group());
        }

------解决方案--------------------
Java code
(?i)https?://[^'">\s]+