zoukankan      html  css  js  c++  java
  • 从一段文字中提取出uri信息

    package handle.groupby;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.Reader;
    import java.io.Writer;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import org.mockito.asm.tree.IntInsnNode;
    
    public class GetUrlFromString {
    
        @SuppressWarnings("resource")
        public static void main(String[] args) throws IOException {
            String line="";
            Pattern pattern = Pattern.compile("([\w.]{1}[\w\/.\s]*[\w]{1})",Pattern.CASE_INSENSITIVE);
            
            BufferedReader r= new BufferedReader(new FileReader(args[0]));
            BufferedWriter w=new BufferedWriter(new FileWriter(args[1])) ;
            while ((line=r.readLine())!=null) {
                String source = line;
                 Matcher matcher = pattern.matcher(source);
                    while(matcher.find()){
    //                    System.out.println(matcher.group(matcher.groupCount()));
                        String url=matcher.group(matcher.groupCount());
                        if (url.contains(".")) {
                            String resUrl="";
                            String resUrl2="";
                            if (url.contains("/")) {
                    //这个判断是为了提取出短域名的网站级访问访问信息,不需要可以删掉。
                    //例如从:汉字汉字汉字t.cn/RVIIIj8汉字汉字 中提取出 t.cn/RVIIIj8而不是t.cn
    int i =url.lastIndexOf("/"); int i2 =url.indexOf("/"); if (i==i2) { resUrl=url; }else { resUrl =url.split("/")[0]; } }else { resUrl=url; } //去空格 resUrl= resUrl.replaceAll(" ", ""); w.write(source+"|"+resUrl); w.write(" "); } } } r.close(); w.flush(); w.close(); System.out.println("执行完毕"); } }
  • 相关阅读:
    github创建repo,本地导入git项目到github
    成功的GIT开发分支模型和策略
    示例可重用的web component方式组织angular应用模块
    git deployment strategy
    如何在linux中从源代码编译安装nodejs?
    some resource favor
    学而习之,成就学习
    C# 去掉代码前边空格(格式化代码)
    mvc重定向
    mvc cshtml 中赋值
  • 原文地址:https://www.cnblogs.com/yanghaolie/p/6418779.html
Copyright © 2011-2022 走看看