[Regexp] Howto capture all matches of a single group

Discussion in 'Java' started by ersin.er@gmail.com, Oct 3, 2005.

  1. Guest

    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
     
    , Oct 3, 2005
    #1
    1. Advertising

  2. Ersin Er Guest

    Ersin Er, Oct 3, 2005
    #2
    1. Advertising

  3. Ersin Er Guest

    Ersin Er, Oct 3, 2005
    #3
  4. Guest

    Re: Howto capture all matches of a single group

    OP is confusing a sub-expression with an independant principal
    expression.
    MHO tells that this discussion thread should be aborted.
     
    , Oct 3, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boris Pelakh
    Replies:
    3
    Views:
    474
    Purl Gurl
    Apr 8, 2004
  2. christopher taylor
    Replies:
    0
    Views:
    421
    christopher taylor
    Sep 17, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    379
    7stud --
    Aug 21, 2009
  4. Ersin Er
    Replies:
    8
    Views:
    174
    Sherm Pendley
    Oct 2, 2005
  5. weston
    Replies:
    1
    Views:
    97
    Michael Winter
    Jun 28, 2005
Loading...

Share This Page