[Regexp] Howto capture all matches of a single group

E

ersin.er

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
 
H

HGA03630

OP is confusing a sub-expression with an independant principal
expression.
MHO tells that this discussion thread should be aborted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top