Monday, 15 February 2010

Regex: Numeric Range java -



Regex: Numeric Range java -

i have little generator wich allows me create string out of regex-expression. high german license plate pretty easy do. ([a-z]{1,3}[- ][a-z]{1,2}[0-9]{1,4}) -> e.g. "cd-b802"

public string generate() { string forreturn = null; (string rule : generator.read(fileregexconfig)) { seek { xeger generator = new xeger(rule); forreturn = generator.generate(); } grab (exception e) { system.err.println(rule + ':' + e.getmessage()); } } homecoming forreturn; } public static string[] read(string str) { list<string> list = new arraylist<string>(); seek { 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(); } grab (exception e) { e.printstacktrace(); } homecoming (string[]) list.toarray(new string[0]); }

the problem have is, how can build regex range of int. illustration seek find way descripe area of validity [37-78].

according http://www.regular-expressions.info/numericranges.html easy describe [0-x] cant find way solve problem. suggestions? in advance!

regexforrange help you:

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

java regex

No comments:

Post a Comment