1

I have a little generator which allows me to create a string out of a regex-expression. For something like a German license plate it is pretty easy to do. ([A-Z]{1,3}[- ][A-Z]{1,2}[0-9]{1,4}) -> e.g. "CD-B802"

public String generate() {
    String forReturn = null;
    for (String rule : Generator.read(fileRegexConfig)) {
        try {
            Xeger generator = new Xeger(rule);
            forReturn  = generator.generate();
        } catch (Exception e) {
            System.err.println(rule + ':' + e.getMessage());
        }
    }
    return forReturn;
}

public static String[] read(String str) {
    List<String> list = new ArrayList<String>();
    try {
        BufferedReader in = new BufferedReader(new FileReader(str));
        String zeile = null;
        while ((zeile = in.readLine()) != null) {
            if (zeile != null && zeile.trim().length() > 0)
                list.add(zeile);
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (String[]) list.toArray(new String[0]);
}

The Problem I have is, how can I build a regex for a range of int. For example I try to find a way to describe an area of validity like [37-78].

according to http://www.regular-expressions.info/numericranges.html it is easy to describe [0-x] but I can't find a way to solve my problem.

1 Answer 1

3

RegexForRange could help you:

To match the range [37;78]: (3[7-9]|[4-6][0-9]|7[0-8])

Sign up to request clarification or add additional context in comments.

1 Comment

+1 Thanks sp00m, didn't know this site. Jan's RegexMagic does the same thing I believe, but this is free and the interface is terrific. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.