Thursday, 15 May 2014

Java regex missing values -



Java regex missing values -

i must confess, i'm pretty useless when comes writing regular expressions, i've got problem that's confusing me.

i have written function takes string input (22k in size) , performs single regex on it, looking long values. 1 long value has been found, replaced string value hashmap.

however, keeps on missing values within string, regex have written is:

pattern.compile("[*]{3}[0-9]{1,}[*]{3}");

the long values i'm searching in file formatted such:

***nnnnnnnnnnnnnnnn***

now regex seems work, said, misses values, example:

***1407374883553285*** - found ***281474976720057*** - not found

i'm quite confused why it's missing values, i'm using simple while loop search, , matcher.find() when match.

i'm assuming either regex isn't strict enough, or it's missing values due way info structured in input string.

if can offer advice, i'd appreciate it.

thanks

a cleaner regex [*]{3}\d+[*]{3}. check against next see how goes:

final pattern pattern = pattern.compile("[*]{3}\\d+[*]{3}"); final matcher matcher = pattern.matcher("inputfile"); while (matcher.find()) { system.out.println(matcher.group()); }

java regex pattern-matching

No comments:

Post a Comment