Menu

multiple group occurences

Help
2003-03-11
2003-03-13
  • Nobody/Anonymous

    Hi,

    I'd like to know if it is possible to retrieve values previously captured by a group, when that group has multiple occurences in a Pattern.
    For example, say I have a pattern
    ({A}\\w{1})({B}\\w{1}){3}({E}\\w{1})
    containing named groups A, B and E.
    If I try to match the String ABCDE, it will produce a match. But when I want to retrieve the values, group A will contain value A, group B contains D and group E contains E, when I use the group(String groupName) method. In other words, I get only the value of the last occurence of group B. Is there any way I can retrieve both other values (B and C)?

    Thanx in advance,

    Abelhinha

     
    • Sergey A. Samokhodkin

      Hi!

      Answer: no.
      The workaround is to capture possible values of B into a single group (i.e. "({B}\\w{3})" ) and analize it with another expression.

      Regards

       
    • Nobody/Anonymous

      Hi,

      Thanks for the quick reply, even though it's not the answer I hoped for:-)

      I'm not sure that capturing the multiple occurrences in one group will solve my problem, since the reason I wanted multiple occurrences in the first place, is that group B contained named subgroups, with names that are meaningfull (fields of a table, the multiple occurrences referring to multiple rows in the table), but I can't have duplicate group names. I guess the only way out will be to append my own numbering to the subgroups, and deal with them that way.

      Thanks again,

      Abelhinha

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.