Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-23-2008, 01:10 AM
Member
 
Join Date: Apr 2008
Posts: 9
hiklior is on a distinguished road
Regular Expression Challange
i need to creat a little regular expression here are the conditions, I know i looks weired but this is what i need.
Any help will be appreciated
First, i need to find 35 consecutive zeros(00000000000000000000000000000000000) from a text file and they could be more than one place. If i find them i need 9th 10th and 11th position value and then put a space then i need 16th and 17th position value and then a space and then 18th and 19th position value and then put a space and then those 35 zeros.
Example
11135781222111122330000000000000000000000000000000 00000
Output should be
222 22 33 00000000000000000000000000000000000

I hope this makes sense
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-23-2008, 05:02 AM
xfrag's Avatar
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.
|
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-24-2008, 06:05 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 526
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Try to have an experiment about split(String regex) method
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression for unicode tharhan Advanced Java 0 04-01-2008 11:53 PM
Regular expression for file path ravian New To Java 3 01-25-2008 09:24 PM
Regular expression with Unions Java Tip Java Tips 0 01-09-2008 01:03 PM
Regular expression with Intersections Java Tip Java Tips 0 01-09-2008 01:03 PM
I can't find the right regular expression romina New To Java 1 08-07-2007 06:36 AM


All times are GMT +3. The time now is 12:27 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org