Results 1 to 3 of 3
Thread: Regular Expression Help Needed
- 01-18-2012, 10:35 PM #1
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Regular Expression Help Needed
I have a string that i am trying to return from a regular expression using the split method. The problem is when it displays, it does so with an empty line on the first line and then displays exactly what i need. The problem is that the empty line is [0] and i cannot figure out a way to make the method not display the first empty line. If you run this you will see that it displays a blank line and then displays a few lines of text. I need the blank line gone. Code below
Java Code:public static void stringTrim(){ String str = "? ? today December 2011 monthweekday Sun 1/15 Mon 1/16 Tue 1/17 Wed 1/18 Thu 1/19 Fri 1/20 Sat 1/21 Sun Mon Tue Wed Thu Fri Sat 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 9a Any Time Test2 Testing9679 Call back 9a Any Time ALLISON MORI Call back 9a Any Time DEWEY DUCK notes notez notes 9:30a Any Time Refinance Harp TASK TEST 10a Any Time J April TASK TEST 10:30a Any Time Bugs Bunny Call back 9a Any Time TESTTESTTEST TESTTESTTESTTEST Call back 9a Any Time john cocktsten Call back 9a Any Time NICHOLAUS JOHNSON TASK TEST 9a Any Time GUADALUPE TREVINO Call back 9:30a Any Time TESTINGA EVERBANK TASK TEST 9:30a Any Time KRYSTAL LEAKE TASK TEST 9a Any Time Robert sinenomme Call back 9a Any Time ARVIND AGARAWAL TASK TEST "; String result[] = str.replaceAll("(\\? \\? today (January|February|March|April|May|June|July|August|September|October|November|December) \\d{4} monthweekday Sun \\d+/\\d+ Mon \\d+/\\d+ Tue \\d+/\\d+ Wed \\d+/\\d+ Thu \\d+/\\d+ Fri \\d+/\\d+ Sat \\d+/\\d+ )|(Sun Mon Tue Wed Thu Fri Sat( \\d{1,2})+)(?![a|p])","").split("(?=(?<![0-9\\:])(\\d+(\\:\\d+)?(a|p)\\s)(?![0-9\\:]))"); List<String> wordlist = Arrays.asList(result); for (Iterator<String> it = wordlist.iterator(); it.hasNext();) { String s = it.next(); String strim = s.trim(); System.out.println(strim); } }
- 01-18-2012, 10:55 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Regular Expression Help Needed
Can you please try:
is there no way to parse this clean? that looks a bit ugly for me :( (maybe with Matcher and Pattern? ...)Java Code:String str = "? ? today December 2011 monthweekday Sun 1/15 Mon 1/16 Tue 1/17 Wed 1/18 Thu 1/19 Fri 1/20 Sat 1/21 Sun Mon Tue Wed Thu Fri Sat 27 28 29 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 9a Any Time Test2 Testing9679 Call back 9a Any Time ALLISON MORI Call back 9a Any Time DEWEY DUCK notes notez notes 9:30a Any Time Refinance Harp TASK TEST 10a Any Time J April TASK TEST 10:30a Any Time Bugs Bunny Call back 9a Any Time TESTTESTTEST TESTTESTTESTTEST Call back 9a Any Time john cocktsten Call back 9a Any Time NICHOLAUS JOHNSON TASK TEST 9a Any Time GUADALUPE TREVINO Call back 9:30a Any Time TESTINGA EVERBANK TASK TEST 9:30a Any Time KRYSTAL LEAKE TASK TEST 9a Any Time Robert sinenomme Call back 9a Any Time ARVIND AGARAWAL TASK TEST "; String result[] = str.replaceAll("(\\? \\? today (January|February|March|April|May|June|July|August|September|October|November|December) \\d{4} monthweekday Sun \\d+/\\d+ Mon \\d+/\\d+ Tue \\d+/\\d+ Wed \\d+/\\d+ Thu \\d+/\\d+ Fri \\d+/\\d+ Sat \\d+/\\d+ )|(Sun Mon Tue Wed Thu Fri Sat( \\d{1,2})+)(?![a|p])","").substring(1).split(" (?=(?<![0-9\\:])(\\d+(\\:\\d+)?(a|p)\\s)(?![0-9\\:]))"); for (String string : result) { System.out.println(string.trim()); }Last edited by eRaaaa; 01-18-2012 at 11:08 PM.
- 01-18-2012, 11:07 PM #3
Member
- Join Date
- May 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Java regular expression optimization - help needed
By dpkcv in forum Advanced JavaReplies: 0Last Post: 09-30-2011, 08:42 AM -
Regular Expression Help
By niketanand in forum Advanced JavaReplies: 1Last Post: 06-24-2011, 04:56 PM -
Regular Expression Help needed PLease!!
By hariz2410 in forum New To JavaReplies: 4Last Post: 12-14-2010, 09:46 PM -
regular expression
By prof.deedee in forum JDBCReplies: 3Last Post: 02-19-2010, 11:15 AM -
regular expression
By ras_pari in forum Advanced JavaReplies: 27Last Post: 10-07-2009, 12:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks