language: Java (sun-jdk-1.7.0_10)
date: 1061 days 2 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.NoSuchElementException;
import java.util.regex.*;
 
public class Main {
        static void dump(String[] ss) {
            for (String s: ss) {
                System.out.print("[" + s + "]");
            }
            System.out.println();
        }
        static String[] partition(String s, String regex) {
                Matcher m = Pattern.compile(regex).matcher(s);
                if (m.find()) {
                        return new String[] {
                                s.substring(0, m.start()),
                                m.group(),
                                s.substring(m.end()),
                        };
                } else {
                        throw new NoSuchElementException("Can't partition!");
                }
        }
        public static void main(String[] args) {
                dump(partition("james007bond111", "\\d+"));
        }
}