Skip to content

Instantly share code, notes, and snippets.

@webstory
Created March 23, 2018 08:14

Revisions

  1. webstory created this gist Mar 23, 2018.
    21 changes: 21 additions & 0 deletions Main.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import java.util.regex.Pattern;
    import java.util.regex.Matcher;

    class Main {
    public static void main(String[] args) {
    String s = "여기는.어디.입니까-12";
    Pattern p = Pattern.compile("^([^.]+\\.[^.]+\\.[^-.]+)(?:-([0-9]{2}))?$");
    Matcher m = p.matcher(s);

    if(m.find()) {
    String wordonly = m.group(1);
    String cellNum = m.group(2);

    System.out.println(wordonly);
    if(cellNum != null) { System.out.println(cellNum); }
    else { System.out.println("44"); }
    } else {
    System.out.println("Malformed 3word");
    }
    }
    }