Example usage for java.lang String replaceAll

List of usage examples for java.lang String replaceAll

Introduction

In this page you can find the example usage for java.lang String replaceAll.

Prototype

public String replaceAll(String regex, String replacement) 

Source Link

Document

Replaces each substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:TheReplacements.java

public static void main(String[] args) throws Exception {
    String s = TextFile.read("TheReplacements.java");
    // Match the specially-commented block of text above:
    Matcher mInput = Pattern.compile("/\\*!(.*)!\\*/", Pattern.DOTALL).matcher(s);
    if (mInput.find())
        s = mInput.group(1); // Captured by parentheses
    // Replace two or more spaces with a single space:
    s = s.replaceAll(" {2,}", " ");
    // Replace one or more spaces at the beginning of each
    // line with no spaces. Must enable MULTILINE mode:
    s = s.replaceAll("(?m)^ +", "");
    System.out.println(s);/*from   w  w w .  ja v  a 2 s. c om*/
    s = s.replaceFirst("[aeiou]", "(VOWEL1)");
    StringBuffer sbuf = new StringBuffer();
    Pattern p = Pattern.compile("[aeiou]");
    Matcher m = p.matcher(s);
    // Process the find information as you
    // perform the replacements:
    while (m.find())
        m.appendReplacement(sbuf, m.group().toUpperCase());
    // Put in the remainder of the text:
    m.appendTail(sbuf);
    System.out.println(sbuf);

}

From source file:com.thesmartweb.vivliocrawlermaven.VivlioCrawlerMavenMain.java

/**
 * @param args the command line arguments
 *///from   w w w.j a va2s  .  c  om
public static void main(String[] args) {
    // TODO code application logic here
    try {

        OaiPmhServer server = new OaiPmhServer("http://vivliothmmy.ee.auth.gr/cgi/oai2");
        RecordsList listRecords = server.listRecords("oai_dc");//we capture all the records in oai dc format
        List<VivlioCrawlerMavenMain> listtotal = new ArrayList<VivlioCrawlerMavenMain>();
        //we capture all the names of the professors and former professor of ECE of AUTH from a txt file
        //change the directory to yours
        List<String> profs = Files.readAllLines(Paths.get(
                "/home/themis/NetBeansProjects/VivlioCrawlerMaven/src/main/java/com/thesmartweb/vivliocrawlermaven/profs.txt"));

        boolean more = true;//it is a flag used if we encounter more entries than the initial capture
        JSONArray array = new JSONArray();//it is going to be our final total json array
        JSONObject jsonObject = new JSONObject();//it is going to be our final total json object
        while (more) {
            for (Record rec : listRecords.asList()) {
                VivlioCrawlerMavenMain vc = new VivlioCrawlerMavenMain();
                Element metadata = rec.getMetadata();
                if (metadata != null) {
                    //System.out.println(rec.getMetadataAsString());
                    List<Element> elements = metadata.elements();
                    //System.out.println(metadata.getStringValue());
                    for (Element element : elements) {
                        String name = element.getName();
                        //we get the title, remove \r, \n and beginning and trailing whitespace
                        if (name.equalsIgnoreCase("title")) {
                            vc.title = element.getStringValue();
                            vc.title = vc.title.trim();
                            vc.title = vc.title.replaceAll("(\\r|\\n)", "");
                            if (!(vc.title.endsWith("."))) {
                                vc.title = vc.title + ".";//we also add dot in the end for the titles to be uniformed
                            }
                        }
                        if (name.equalsIgnoreCase("creator")) {
                            vc.creators.add(element.getStringValue());//we capture the students' names
                        }
                        if (name.equalsIgnoreCase("subject")) {
                            vc.subjects.add(element.getStringValue());//we capture the subjects
                        }
                        if (name.equalsIgnoreCase("description")) {
                            vc.description = element.getStringValue();//we capture the abstract
                        }
                        if (name.equalsIgnoreCase("date")) {
                            vc.datestring = element.getStringValue();
                        }
                        if (name.equalsIgnoreCase("identifier")) {
                            if (element.getStringValue().contains("http://")) {
                                vc.thesisFiles.add(element.getStringValue());//we capture the url of the thesis whole file
                                if (vc.thesisURL == null) {
                                    vc.thesisURL = element.getStringValue().substring(0, 32);
                                }
                            }
                            //if the identifier contains the title then it must be the citation 
                            //out of the citation we need to extract the supevisor's name
                            if (element.getStringValue().contains(vc.title.substring(0, 10))) {
                                vc.citation = element.getStringValue();
                                vc.supervisor = element.getStringValue();
                                Iterator profsIterator = profs.iterator();
                                vc.supervisor = vc.supervisor.replace(vc.title, "");//we remove the title out of the citation
                                //if we have two students we remove the first occurence of "" which stands for "and"
                                if (vc.creators.size() == 2) {
                                    vc.supervisor = vc.supervisor.replaceFirst("", "");
                                }
                                //we remove the students' names
                                Iterator creatorsIterator = vc.creators.iterator();
                                while (creatorsIterator.hasNext()) {
                                    vc.supervisor = vc.supervisor.replace(creatorsIterator.next().toString(),
                                            "");
                                }
                                boolean profFlag = false;//flag used that declares that we found the professor that was supervisor
                                while (profsIterator.hasNext() && !profFlag) {
                                    String prof = profsIterator.next().toString();
                                    //we split the professor's name to surname and name
                                    //because some entries have first the surname and others first the name
                                    String[] profSplitted = prof.split("\\s+");
                                    String supervisorCleared = vc.supervisor;
                                    supervisorCleared = supervisorCleared.replaceAll("\\s+", "");//we clear the white space
                                    supervisorCleared = supervisorCleared.replaceAll("(\\r|\\n)", "");//we remove the \r\n
                                    //now we check if the citation includes any name of the professors from the txt
                                    if (supervisorCleared.contains(profSplitted[0])
                                            && supervisorCleared.contains(profSplitted[1])) {
                                        vc.supervisor = prof;
                                        profFlag = true;
                                    }
                                }
                                //if we don't find the name of the supervisor, we have to perform string manipulation to extract it
                                if (!profFlag) {
                                    vc.supervisor = vc.supervisor.trim();
                                    //we remove the word "" which stands for "Thessaloniki" and "" which stands for Greece
                                    if (vc.supervisor.contains("")) {
                                        vc.supervisor = vc.supervisor.replaceFirst("",
                                                "");
                                    }
                                    if (vc.supervisor.contains("")) {
                                        vc.supervisor = vc.supervisor.replaceFirst("",
                                                "");
                                    }
                                    if (vc.supervisor.contains("")) {
                                        vc.supervisor = vc.supervisor.replaceFirst("", "");
                                    }
                                    if (vc.supervisor.contains("")) {
                                        vc.supervisor = vc.supervisor.replaceFirst("", "");
                                    }
                                    //we remove the year and then we should be left only with the supervisor's name
                                    vc.supervisor = vc.supervisor.replace("(", "");
                                    vc.supervisor = vc.supervisor.trim();
                                    vc.supervisor = vc.supervisor.replace(")", "");
                                    vc.supervisor = vc.supervisor.trim();
                                    vc.supervisor = vc.supervisor.replace(",", "");
                                    vc.supervisor = vc.supervisor.trim();
                                    vc.supervisor = vc.supervisor.replace(".", "");
                                    vc.supervisor = vc.supervisor.trim();
                                    vc.supervisor = vc.supervisor.replace(vc.datestring.substring(0, 4), "");
                                    vc.supervisor = vc.supervisor.trim();
                                }
                                //we put everything in a json object
                                JSONObject obj = new JSONObject();
                                obj.put("title", vc.title);
                                obj.put("description", vc.description);
                                JSONArray creatorsArray = new JSONArray();
                                creatorsArray.add(vc.creators);
                                obj.put("creators", creatorsArray);
                                JSONArray subjectsArray = new JSONArray();
                                List<String> subjectsList = new ArrayList<String>(vc.subjects);
                                subjectsArray.add(subjectsList);
                                obj.put("subjects", subjectsArray);
                                obj.put("datestring", vc.datestring);
                                JSONArray thesisFilesArray = new JSONArray();
                                thesisFilesArray.add(vc.thesisFiles);
                                obj.put("thesisFiles", thesisFilesArray);
                                obj.put("thesisURL", vc.thesisURL);
                                obj.put("supervisor", vc.supervisor);
                                obj.put("citation", vc.citation);
                                //if you are using JSON.simple do this
                                array.add(obj);
                            }
                        }
                    }
                    listtotal.add(vc);//a list containing all the objects
                    //it is not used for now, but created for potential extension of the work
                }
            }
            //the following if clause searches for new records
            if (listRecords.getResumptionToken() != null) {
                listRecords = server.listRecords(listRecords.getResumptionToken());
            } else {
                more = false;
            }
        }
        //we print which records did not have a supervisor
        for (VivlioCrawlerMavenMain vctest : listtotal) {

            if (vctest.supervisor == null) {
                System.out.println(vctest.title);
                System.out.println(vctest.citation);
            }
        }
        //we create a pretty json with GSON and we write it into a file
        jsonObject.put("VivliothmmyOldArray", array);
        JsonParser parser = new JsonParser();
        JsonObject json = parser.parse(jsonObject.toJSONString()).getAsJsonObject();
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String prettyJson = gson.toJson(json);
        try {

            FileWriter file = new FileWriter(
                    "/home/themis/NetBeansProjects/VivlioCrawlerMaven/src/main/java/com/thesmartweb/vivliocrawlermaven/VivliothmmyOldRecords.json");
            file.write(prettyJson);
            file.flush();
            file.close();

        } catch (IOException e) {
            System.out.println("Exception: " + e);
        }

        //System.out.print(prettyJson);

        //int j=0;

    } catch (OAIException | IOException e) {
        System.out.println("Exception: " + e);
    }
}

From source file:eu.fbk.dkm.sectionextractor.WikipediaSectionTitlesExtractor.java

public static void main(String args[]) throws IOException {

    CommandLineWithLogger commandLineWithLogger = new CommandLineWithLogger();
    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg()
            .withDescription("wikipedia xml dump file").isRequired().withLongOpt("wikipedia-dump").create("d"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("file").hasArg().withDescription("Filter file")
            .withLongOpt("filter").create("f"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("output file")
            .isRequired().withLongOpt("output-file").create("o"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("max depth (default " + MAX_DEPTH + ")").withLongOpt("max-depth").create("m"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("max num of sections").withLongOpt("max-num").create("n"));
    commandLineWithLogger.addOption(new Option("l", "print titles"));

    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription(// w  w  w. ja va  2 s .  co m
                    "number of threads (default " + AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER + ")")
            .withLongOpt("num-threads").create("t"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("number of pages to process (default all)").withLongOpt("num-pages").create("p"));
    commandLineWithLogger.addOption(OptionBuilder.withArgName("int").hasArg()
            .withDescription("receive notification every n pages (default "
                    + AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT + ")")
            .withLongOpt("notification-point").create("b"));

    CommandLine commandLine = null;
    try {
        commandLine = commandLineWithLogger.getCommandLine(args);
        PropertyConfigurator.configure(commandLineWithLogger.getLoggerProps());
    } catch (Exception e) {
        System.exit(1);
    }

    int numThreads = Integer.parseInt(commandLine.getOptionValue("num-threads",
            Integer.toString(AbstractWikipediaXmlDumpParser.DEFAULT_THREADS_NUMBER)));
    int numPages = Integer.parseInt(commandLine.getOptionValue("num-pages",
            Integer.toString(AbstractWikipediaExtractor.DEFAULT_NUM_PAGES)));
    int notificationPoint = Integer.parseInt(commandLine.getOptionValue("notification-point",
            Integer.toString(AbstractWikipediaExtractor.DEFAULT_NOTIFICATION_POINT)));

    int configuredDepth = Integer
            .parseInt(commandLine.getOptionValue("max-depth", Integer.toString(MAX_DEPTH)));
    int maxNum = Integer.parseInt(commandLine.getOptionValue("max-num", "0"));
    boolean printTitles = commandLine.hasOption("l");

    HashSet<String> pagesToConsider = null;
    String filterFileName = commandLine.getOptionValue("filter");
    if (filterFileName != null) {
        File filterFile = new File(filterFileName);
        if (filterFile.exists()) {
            pagesToConsider = new HashSet<>();
            List<String> lines = Files.readLines(filterFile, Charsets.UTF_8);
            for (String line : lines) {
                line = line.trim();
                if (line.length() == 0) {
                    continue;
                }

                line = line.replaceAll("\\s+", "_");

                pagesToConsider.add(line);
            }
        }
    }

    File outputFile = new File(commandLine.getOptionValue("output-file"));
    ExtractorParameters extractorParameters = new ExtractorParameters(
            commandLine.getOptionValue("wikipedia-dump"), outputFile.getAbsolutePath());

    WikipediaExtractor wikipediaPageParser = new WikipediaSectionTitlesExtractor(numThreads, numPages,
            extractorParameters.getLocale(), outputFile, configuredDepth, maxNum, printTitles, pagesToConsider);
    wikipediaPageParser.setNotificationPoint(notificationPoint);
    wikipediaPageParser.start(extractorParameters);

    logger.info("extraction ended " + new Date());

}

From source file:com.da.daum.DaumCafeOneLineParser.java

public static void main(String[] args) throws IOException {
    DaumCafeOneLineParser parser = new DaumCafeOneLineParser();
    String listBody = "(?)^*~.txt";
    listBody = listBody.replaceAll("\\*", "").replaceAll("\\*", "");
    System.out.println(listBody);
    // FileUtils.writeStringToFile(new File(file), listBody, "utf-8");
    // File file = new File("C:\\TEMP\\daum\\user\\Lak_view_.txt");
    File file = new File("C:\\TEMP\\daum\\user\\Lak_list_1.txt");
    listBody = FileUtils.readFileToString(file, "utf-8");
    Map pageMap = new HashMap();
    parser.setDaumListVoList(listBody, pageMap);
    // parser.setDaumView(listBody);

}

From source file:com.verizon.Main.java

public static void main(String[] args) throws Exception {

    String warehouseLocation = "file:" + System.getProperty("user.dir") + "spark-warehouse";

    SparkSession spark = SparkSession.builder().appName("Verizon").config("spark.master", "local[2]")
            .config("spark.sql.warehouse.dir", warehouseLocation).enableHiveSupport().getOrCreate();

    Configuration configuration = new Configuration();
    configuration.addResource(new Path(System.getProperty("HADOOP_INSTALL") + "/conf/core-site.xml"));
    configuration.addResource(new Path(System.getProperty("HADOOP_INSTALL") + "/conf/hdfs-site.xml"));
    configuration.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
    configuration.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());

    FileSystem hdfs = FileSystem.get(new URI("hdfs://localhost:9000"), configuration);

    SQLContext context = new SQLContext(spark);
    String schemaString = " Device,Title,ReviewText,SubmissionTime,UserNickname";
    //spark.read().textFile(schemaString)
    Dataset<Row> df = spark.read().csv("hdfs://localhost:9000/data.csv");
    //df.show();/* w ww. j  a  v a  2 s.co  m*/
    //#df.printSchema();
    df = df.select("_c2");

    Path file = new Path("hdfs://localhost:9000/tempFile.txt");
    if (hdfs.exists(file)) {
        hdfs.delete(file, true);
    }

    df.write().csv("hdfs://localhost:9000/tempFile.txt");

    JavaRDD<String> lines = spark.read().textFile("hdfs://localhost:9000/tempFile.txt").javaRDD();
    JavaRDD<String> words = lines.flatMap(new FlatMapFunction<String, String>() {
        @Override
        public Iterator<String> call(String s) {
            return Arrays.asList(SPACE.split(s)).iterator();
        }
    });

    JavaPairRDD<String, Integer> ones = words.mapToPair(new PairFunction<String, String, Integer>() {
        @Override
        public Tuple2<String, Integer> call(String s) {
            s = s.replaceAll("[^a-zA-Z0-9]+", "");
            s = s.toLowerCase().trim();
            return new Tuple2<>(s, 1);
        }
    });

    JavaPairRDD<String, Integer> counts = ones.reduceByKey(new Function2<Integer, Integer, Integer>() {
        @Override
        public Integer call(Integer i1, Integer i2) {
            return i1 + i2;
        }
    });

    JavaPairRDD<Integer, String> frequencies = counts
            .mapToPair(new PairFunction<Tuple2<String, Integer>, Integer, String>() {
                @Override
                public Tuple2<Integer, String> call(Tuple2<String, Integer> s) {
                    return new Tuple2<Integer, String>(s._2, s._1);
                }
            });

    frequencies = frequencies.sortByKey(false);

    JavaPairRDD<String, Integer> result = frequencies
            .mapToPair(new PairFunction<Tuple2<Integer, String>, String, Integer>() {
                @Override
                public Tuple2<String, Integer> call(Tuple2<Integer, String> s) throws Exception {
                    return new Tuple2<String, Integer>(s._2, s._1);
                }

            });

    //JavaPairRDD<Integer,String> sortedByFreq = sort(frequencies, "descending"); 
    file = new Path("hdfs://localhost:9000/allresult.csv");
    if (hdfs.exists(file)) {
        hdfs.delete(file, true);
    }

    //FileUtils.deleteDirectory(new File("allresult.csv"));

    result.saveAsTextFile("hdfs://localhost:9000/allresult.csv");

    List<Tuple2<String, Integer>> output = result.take(250);

    ExportToHive hiveExport = new ExportToHive();
    String rows = "";
    for (Tuple2<String, Integer> tuple : output) {
        String date = new Date().toString();
        String keyword = tuple._1();
        Integer count = tuple._2();
        //System.out.println( keyword+ "," +count);
        rows += date + "," + "Samsung Galaxy s7," + keyword + "," + count + System.lineSeparator();

    }
    //System.out.println(rows);
    /*
    file = new Path("hdfs://localhost:9000/result.csv");
            
    if ( hdfs.exists( file )) { hdfs.delete( file, true ); } 
    OutputStream os = hdfs.create(file);
    BufferedWriter br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) );
    br.write(rows);
    br.close();
    */
    hdfs.close();

    FileUtils.deleteQuietly(new File("result.csv"));
    FileUtils.writeStringToFile(new File("result.csv"), rows);

    hiveExport.writeToHive(spark);
    ExportDataToServer exportServer = new ExportDataToServer();
    exportServer.sendDataToRESTService(rows);
    spark.stop();
}

From source file:com.cisco.dbds.utils.report.CustomReport.java

/**
 * The main method./*from   ww  w.  j  a v a2s  . com*/
 *
 * @param args the arguments
 * @throws FileNotFoundException the file not found exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws ParseException the parse exception
 * @throws AddressException the address exception
 */
public static void main(String[] args)
        throws FileNotFoundException, IOException, ParseException, AddressException {

    // reportparsejson();
    String msg = reportparsejson();
    sendmail(msg);
    String eol = System.getProperty("line.separator");
    //msg=msg.replaceAll("</tr>", eol+"</tr>");
    msg = msg.replaceAll("<tr", eol + "<tr");
    msg = msg.replaceAll("</table>", eol + "</table>");
    msg = msg.replaceAll("<table", eol + "<table");
    new FileOutputStream(htmlfname).close();
    htmlfile = new PrintWriter(new BufferedWriter(new FileWriter(htmlfname, true)));

    htmlfile.print(msg);
    htmlfile.close();

    // String mailContent = "Hi All<br>"+
    // "Build Tag id: jenkins-CANEAS-Nightly-Completed-190 has been completed and the run reports  found in the link: http://10.78.216.52:8080/job/CANEAS-Nightly-Completed/190/cucumber-html-reports/"
    // + "<br>"
    // +
    //
    // "EDCS link for failure analysis Reasons: http://wwwin-eng.cisco.com/cgi-bin/edcs/edcs_info?3677074"
    // + "<br>"
    // +
    // "(will be updated soon for the Build: jenkins-CANEAS-Nightly-Completed-190 )"
    // + "<br><br>" + "Regards" + "<br>" + "SIT Automation TEAM"
    // + "<br>";
    // sendmail(mailContent);
}

From source file:com.asakusafw.generator.HadoopBulkLoaderDDLGenerator.java

/**
 * HadoopBulkLoader?????/*from  ww  w .j  a  v  a  2 s  .c o  m*/
 *
 * @param args
 *            ??
 * @throws Exception
 *             ??????
 */
public static void main(String[] args) throws Exception {
    String outputTablesString = findVariable(ENV_BULKLOADER_TABLES, true);
    List<String> outputTableList = null;
    if (outputTablesString != null && !OUTPUT_TABLES_PROPERTY.equals(outputTablesString)) {
        String[] outputTables = outputTablesString.trim().split("\\s+");
        outputTableList = Arrays.asList(outputTables);
    }

    String ddlTemplate;
    InputStream in = HadoopBulkLoaderDDLGenerator.class.getResourceAsStream(TEMPLATE_DDL_FILENAME);
    try {
        ddlTemplate = IOUtils.toString(in);
    } finally {
        in.close();
    }
    StringBuilder sb = new StringBuilder();

    for (String tableName : args) {
        if (outputTableList == null || outputTableList.contains(tableName)) {
            String tableddl = ddlTemplate.replaceAll(TABLENAME_REPLACE_STRING, tableName);
            sb.append(tableddl);
        }
    }

    String outputFilePath = findVariable(ENV_BULKLOADER_GENDDL, true);
    if (outputFilePath == null) {
        throw new RuntimeException(
                "ASAKUSA_BULKLOADER_TABLES???????");
    }
    FileUtils.write(new File(outputFilePath), sb);
}

From source file:GoogleImages.java

public static void main(String[] args) throws InterruptedException {
    String searchTerm = "s woman"; // term to search for (use spaces to separate terms)
    int offset = 40; // we can only 20 results at a time - use this to offset and get more!
    String fileSize = "50mp"; // specify file size in mexapixels (S/M/L not figured out yet)
    String source = null; // string to save raw HTML source code

    // format spaces in URL to avoid problems
    searchTerm = searchTerm.replaceAll(" ", "%20");

    // get Google image search HTML source code; mostly built from PhyloWidget example:
    // http://code.google.com/p/phylowidget/source/browse/trunk/PhyloWidget/src/org/phylowidget/render/images/ImageSearcher.java
    int offset2 = 0;
    Set urlsss = new HashSet<String>();
    while (offset2 < 600) {
        try {/*from www  .  j a v  a 2  s .  c o m*/
            URL query = new URL("https://www.google.ru/search?start=" + offset2
                    + "&q=angry+woman&newwindow=1&client=opera&hs=bPE&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiAgcKozIfNAhWoHJoKHSb_AUoQ_AUIBygB&biw=1517&bih=731&dpr=0.9#imgrc=G_1tH3YOPcc8KM%3A");
            HttpURLConnection urlc = (HttpURLConnection) query.openConnection(); // start connection...
            urlc.setInstanceFollowRedirects(true);
            urlc.setRequestProperty("User-Agent", "");
            urlc.connect();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); // stream in HTTP source to file
            StringBuffer response = new StringBuffer();
            char[] buffer = new char[1024];
            while (true) {
                int charsRead = in.read(buffer);
                if (charsRead == -1) {
                    break;
                }
                response.append(buffer, 0, charsRead);
            }
            in.close(); // close input stream (also closes network connection)
            source = response.toString();
        } // any problems connecting? let us know
        catch (Exception e) {
            e.printStackTrace();
        }

        // print full source code (for debugging)
        // println(source);
        // extract image URLs only, starting with 'imgurl'
        if (source != null) {
            //                System.out.println(source);
            int c = StringUtils.countMatches(source, "http://www.vmir.su");
            System.out.println(c);
            int index = source.indexOf("src=");
            System.out.println(source.subSequence(index, index + 200));
            while (index >= 0) {
                System.out.println(index);
                index = source.indexOf("src=", index + 1);
                if (index == -1) {
                    break;
                }
                String rr = source.substring(index,
                        index + 200 > source.length() ? source.length() : index + 200);

                if (rr.contains("\"")) {
                    rr = rr.substring(5, rr.indexOf("\"", 5));
                }
                System.out.println(rr);
                urlsss.add(rr);
            }
        }
        offset2 += 20;
        Thread.sleep(1000);
        System.out.println("off set = " + offset2);

    }

    System.out.println(urlsss);
    urlsss.forEach(new Consumer<String>() {

        public void accept(String s) {
            try {
                saveImage(s, "C:\\Users\\Java\\Desktop\\ang\\" + UUID.randomUUID().toString() + ".jpg");
            } catch (IOException ex) {
                Logger.getLogger(GoogleImages.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    //            String[][] m = matchAll(source, "img height=\"\\d+\" src=\"([^\"]+)\"");

    // older regex, no longer working but left for posterity
    // built partially from: http://www.mkyong.com/regular-expressions/how-to-validate-image-file-extension-with-regular-expression
    // String[][] m = matchAll(source, "imgurl=(.*?\\.(?i)(jpg|jpeg|png|gif|bmp|tif|tiff))");    // (?i) means case-insensitive
    //            for (int i = 0; i < m.length; i++) {                                                          // iterate all results of the match
    //                println(i + ":\t" + m[i][1]);                                                         // print (or store them)**
    //            }
}

From source file:de.mpg.escidoc.services.edoc.BatchUpdate.java

/**
 * @param args//from w  ww.j ava  2 s .c  om
 */
public static void main(String[] args) throws Exception {
    CORESERVICES_URL = PropertyReader.getProperty("escidoc.framework_access.framework.url");

    String userHandle = AdminHelper.loginUser("import_user", "");

    logger.info("Querying core-services...");
    HttpClient httpClient = new HttpClient();
    String filter = "<param><filter name=\"http://escidoc.de/core/01/structural-relations/context\">"
            + IMPORT_CONTEXT
            + "</filter><order-by>http://escidoc.de/core/01/properties/creation-date</order-by><limit>0</limit></param>";

    logger.info("Filter: " + filter);

    PostMethod postMethod = new PostMethod(CORESERVICES_URL + "/ir/items/filter");

    postMethod.setRequestBody(filter);

    ProxyHelper.executeMethod(httpClient, postMethod);

    //        GetMethod getMethod = new GetMethod(CORESERVICES_URL + "/ir/item/escidoc:100220");
    //        getMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle)ProxyHelper.executeMethod(httpClient, getMethod)hod(httpClient, getMethod);

    String response = postMethod.getResponseBodyAsString();
    logger.info("...done!");

    System.out.println(response);

    while (response.contains("<escidocItem:item")) {

        int startPos = response.indexOf("<escidocItem:item");
        int endPos = response.indexOf("</escidocItem:item>");

        String item = response.substring(startPos, endPos + 19);

        response = response.substring(endPos + 19);

        startPos = item.indexOf("xlink:href=\"");
        endPos = item.indexOf("\"", startPos + 12);

        String objId = item.substring(startPos + 12, endPos);

        System.out.print(objId);

        if (item.contains("escidoc:22019")) {
            item = item.replaceAll("escidoc:22019", "escidoc:55222");

            PutMethod putMethod = new PutMethod(CORESERVICES_URL + objId);

            putMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            putMethod.setRequestEntity(new StringRequestEntity(item));
            ProxyHelper.executeMethod(httpClient, putMethod);

            String result = putMethod.getResponseBodyAsString();

            //System.out.println(item);

            startPos = result.indexOf("last-modification-date=\"");
            endPos = result.indexOf("\"", startPos + 24);
            String modDate = result.substring(startPos + 24, endPos);
            //System.out.println("modDate: " + modDate);
            String param = "<param last-modification-date=\"" + modDate
                    + "\"><url>http://pubman.mpdl.mpg.de/pubman/item/" + objId.substring(4) + "</url></param>";
            postMethod = new PostMethod(CORESERVICES_URL + objId + "/assign-version-pid");
            postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            postMethod.setRequestEntity(new StringRequestEntity(param));
            ProxyHelper.executeMethod(httpClient, postMethod);
            result = postMethod.getResponseBodyAsString();
            //System.out.println("Result: " + result);

            startPos = result.indexOf("last-modification-date=\"");
            endPos = result.indexOf("\"", startPos + 24);
            modDate = result.substring(startPos + 24, endPos);
            //System.out.println("modDate: " + modDate);
            param = "<param last-modification-date=\"" + modDate
                    + "\"><comment>Batch repair of organizational unit identifier</comment></param>";
            postMethod = new PostMethod(CORESERVICES_URL + objId + "/submit");
            postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            postMethod.setRequestEntity(new StringRequestEntity(param));
            ProxyHelper.executeMethod(httpClient, postMethod);
            result = postMethod.getResponseBodyAsString();
            //System.out.println("Result: " + result);

            startPos = result.indexOf("last-modification-date=\"");
            endPos = result.indexOf("\"", startPos + 24);
            modDate = result.substring(startPos + 24, endPos);
            //System.out.println("modDate: " + modDate);
            param = "<param last-modification-date=\"" + modDate
                    + "\"><comment>Batch repair of organizational unit identifier</comment></param>";
            postMethod = new PostMethod(CORESERVICES_URL + objId + "/release");
            postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
            postMethod.setRequestEntity(new StringRequestEntity(param));
            ProxyHelper.executeMethod(httpClient, postMethod);
            result = postMethod.getResponseBodyAsString();
            //System.out.println("Result: " + result);
            System.out.println("...changed");
        } else {
            System.out.println("...not affected");
        }
    }

}

From source file:StyleSearchAndReplace.java

public static void main(String args[]) {

    String statement = "The question as to whether the jab is"
            + " superior to the cross has been debated for some time in"
            + " boxing circles. However, it is my opinion that this"
            + " false dichotomy misses the point. I call your attention"
            + " to the fact that the best boxers often use a combination of"
            + " the two. I call your attention to the fact that Mohammed"
            + " Ali,the Greatest of the sport of boxing, used both. He had"
            + " a tremendous jab, yet used his cross effectively, often," + " and well";

    String newStmt = statement.replaceAll("The question as to whether", "Whether");

    newStmt = newStmt.replaceAll(" of the sport of boxing", "");
    newStmt = newStmt.replaceAll("amount of success", "success");
    newStmt = newStmt.replaceAll("However, it is my opinion that this", "This");

    newStmt = newStmt.replaceAll("a combination of the two", "both");
    newStmt = newStmt.replaceAll("This is in spite of the fact that" + " the", "The");
    newStmt = newStmt.replaceAll("I call your attention to the fact that", "");

    System.out.println("BEFORE:\n" + statement + "\n");
    System.out.println("AFTER:\n" + newStmt);
}