Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: laredotornado@gmail.com Newsgroups: comp.lang.java.programmer Subject: Re: Keeping the split token in a Java regular expression Date: Mon, 26 Mar 2012 14:21:07 -0700 (PDT) Organization: http://groups.google.com Lines: 29 Message-ID: <9569964.403.1332796867513.JavaMail.geo-discussion-forums@ynne2> References: <48d35bc3-a391-4ccf-a222-dac64775a2f2@oq7g2000pbb.googlegroups.com> NNTP-Posting-Host: 64.134.35.2 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1332796868 4014 127.0.0.1 (26 Mar 2012 21:21:08 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 26 Mar 2012 21:21:08 +0000 (UTC) In-Reply-To: <48d35bc3-a391-4ccf-a222-dac64775a2f2@oq7g2000pbb.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=64.134.35.2; posting-account=siV97QoAAACYFQde4xADFFFlMTK0JZ44 User-Agent: G2/1.0 Xref: csiph.com comp.lang.java.programmer:13200 On Monday, March 26, 2012 1:54:40 PM UTC-5, laredotornado wrote: > Hi, > > I'm using Java 6. I want to split a Java string on a regular > expression, but I would like to keep part of the string used to split > in the results. What I have are Strings like > > Fri 7:30 PM, Sat 2 PM, Sun 2:30 PM > > What I would like to do is split the expression wherever I have an > expression matching /(am|pm),?/i . Hopefully I got that right. In > the above example, I would like the results to be > > Fri 7:30 PM > Sat 2 PM > Sun 2:30 PM > > But with String.split, the split token is not kept within the > results. How would I write a Java parsing expression to do what I > want? > > Thanks, - Dave Hi, I don't want to split on the comma because there could be a case where the given String is "Fri 8 PM, Sat 1, 3, and 5 PM" and in this case, I want the result to be a String array containing Fri 8 PM Sat 1, 3, and 5 PM Your continued help is appreciated, - Dave