Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [Regexp] Howto capture all matches of a single group

Reply
Thread Tools

[Regexp] Howto capture all matches of a single group

 
 
ersin.er@gmail.com
Guest
Posts: n/a
 
      10-03-2005
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/...attern.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

 
Reply With Quote
 
 
 
 
Ersin Er
Guest
Posts: n/a
 
      10-03-2005
In fact, .NET CaptureCollection is what I really want.

It's explained here:

http://msdn.microsoft.com/library/de...xpressions.asp

Isn't it possible for Java ?

--
Ersin

 
Reply With Quote
 
 
 
 
Ersin Er
Guest
Posts: n/a
 
      10-03-2005

Ersin Er wrote:
> In fact, .NET CaptureCollection is what I really want.
>
> It's explained here:
>
> http://msdn.microsoft.com/library/de...xpressions.asp


Sorry, here:

http://msdn.microsoft.com/library/de...ionclasses.asp

> Isn't it possible for Java ?
>
> --
> Ersin


 
Reply With Quote
 
HGA03630@nifty.ne.jp
Guest
Posts: n/a
 
      10-03-2005
OP is confusing a sub-expression with an independant principal
expression.
MHO tells that this discussion thread should be aborted.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
python regex character group matches...group...gotcha christopher taylor Python 0 09-17-2008 03:31 PM
HOWTO connect my all (three) BT extension sockets to a single ATA(with FSX and PSTN)? dmitri UK VOIP 7 02-06-2007 07:28 PM
Howto capture all matches of a single group Ersin Er Perl Misc 8 10-02-2005 08:50 PM
RegExp doesn't capture matches in parentheses? weston Javascript 1 06-28-2005 10:16 AM
Capturing repeating group matches in regular expressions James Collier Python 4 08-12-2004 10:57 AM



Advertisments