Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Keeping the split token in a Java regular expression Date: Mon, 26 Mar 2012 12:22:45 -0700 (PDT) Organization: http://groups.google.com Lines: 23 Message-ID: <33095746.178.1332789765559.JavaMail.geo-discussion-forums@pbcto7> References: <48d35bc3-a391-4ccf-a222-dac64775a2f2@oq7g2000pbb.googlegroups.com> NNTP-Posting-Host: 69.28.149.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1332789766 26634 127.0.0.1 (26 Mar 2012 19:22:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 26 Mar 2012 19:22:46 +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=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 Xref: csiph.com comp.lang.java.programmer:13193 laredotornado wrote: > 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? Based on what you've shown it looks like you could split on the comma and trim the resulting strings. -- Lew