dimanche 3 juillet 2016

matches method taking a lot of time to execute in regular expressions

Am using regular expression called glob i.e., *.

example:

String str="this is *";

String str1="this is regular Expression";

If we call matches on these strings they should be equal.

Please check the below code which is taking a lot of time for executions.

public static void main(String[] args) {

    String value="NO OTHER GERM CELL COMPONENT. TUMOR DIMENSIONS: **X**X** CM. TUMOR FOCALITY: FOCAL MULTIFOCAL INTRA-TUBULAR GERM CELL NEOPLASIA (ITGN): PRESENT ABSENT SCATTERED SYNCTOIOTROPHOBLASTIC GIANT CELLS PRESENT/NO SCATTERED SYNCYTIOTROPHOBLASTIC GIANT CELLS PRESENT RETE TESTIS INVOLVEMENT BY INVASIVE TUMOR: PRESENT ABSENT EXTENSION BEYOND TUNICA ALBUGINEA: PRESENT ABSENT ANGIOLYMPHATIC INVASION : PRESENT ABSENT SPERMATIC CORD MARGIN: POSITIVE NEGATIVE NECROSIS: PRESENT ABSENT SERUM TUMOR MARKERS: AVAILABLE NOT AVAILABLE PT**NXMXSX (AJCC 2010, SEVENTH EDITION) Appropriately controlled immunohistochemical stains for PLAP, OCT3/4, CD30, C-kit, and Pan cytokeratin were performed on a select representative block **# with following results: PLAP positive, OCT 3/4 positive, CD30 Negative, C-kit positive and Pan cytokeratin negative, supporting the above diagnosis.";
    String str=value;
    if (value.contains("*")) {
        value = value.replace("*", "[\s\S]*");
    }
    if (str.trim().matches(value)) {
        System.out.println("true");
    }else {
        System.out.println("false");
    }
}

Aucun commentaire:

Enregistrer un commentaire