Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

[Regexp] Howto capture all matches of a single group

Thread view: 
ersin.er@gmail.com - 03 Oct 2005 09:07 GMT
Hi,

Say, I have a regexp like (\d)(?:,(\d))* which recognizes inputs like
"1", "0,4", "9,2,0", etc. What I want is to get all captured strings
from group 3 (and also the one from group 1). When the operation has
finished group 3 has only the last captured text which is the last
digit for this case. However I want to get all digits matched by group
1 and 3.

This is stated in API doc as follows:

"The captured input associated with a group is always the subsequence
that the group most recently matched. If a group is evaluated a second
time because of quantification then its previously-captured value, if
any, will be retained if the second evaluation fails. Matching the
string "aba" against the expression (a(b)?)+, for example, leaves group
two set to "b". All captured input is discarded at the beginning of
each match."
(
http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#cg
)

You may advise to use splitting but it does not work for more complex
examples where delimitors are also included in the subgroups several
times.

Any suggestions?

Thanks in advance.

-- Ersin
Ersin Er - 03 Oct 2005 09:23 GMT
In fact, .NET CaptureCollection is what I really want.

It's explained here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
concomregularexpressions.asp


Isn't it possible for Java ?

Signature

Ersin

Ersin Er - 03 Oct 2005 09:25 GMT
> In fact, .NET CaptureCollection is what I really want.
>
> It's explained here:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
concomregularexpressions.asp

Sorry, here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conusingregularexpressionclasses.asp


> Isn't it possible for Java ?
HGA03630@nifty.ne.jp - 03 Oct 2005 11:11 GMT
OP is confusing a sub-expression with an independant principal
expression.
MHO tells that this discussion thread should be aborted.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.