View Single Post
  #2 (permalink)  
Old 04-23-2008, 06:02 AM
xfrag's Avatar
xfrag xfrag is offline
Member
 
Join Date: Apr 2008
Location: Athens, Greece
Posts: 4
xfrag is on a distinguished road
Well I'm not sure I understood correctly what are you trying to do, but I can help you find the zeros. Use the following code:
Code:
try { Pattern p = Pattern.compile("0{2,}"); Matcher m = p.matcher("11135781222111122330000000000000000000000000000000 00000"); int idx = -1; String output = ""; while (!m.hitEnd() && m.find()) { if(idx == -1){ idx = m.start(); } output += m.group(); } if(output.length() >= 35){ System.out.println("Found 35 consecutive zeros:"); System.out.println(output.substring(0,35)); System.out.println("Start index: " + idx); } } catch (Exception matchEx) { System.out.println(matchEx.getMessage()); }
This way you also have the index of the fist zero in the sequence, so you can get the "n-th" characters you're looking for, append them at the front of the output, add spaces where needed and you're done!

Note: I don't know if ALL your requirements can be met using a single regular expression, and I think they cannot.
__________________
X-Frag :: |
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
Reply With Quote