Menu

Multiple Name Groups

Help
LudoO
2004-06-09
2004-06-11
  • LudoO

    LudoO - 2004-06-09

    Named groups is a very good way to retrieve differents elements in a difficult regexpr.
    But is there a way to retrieve multiple named groups :

    I'd like to use a regexpr like this (mine in fact is more complex) :
    ({PAGE}\\d+)\\s?;?)+
    against a text like :
    "10 ; 20 ; 30 ; 40"

    I use
    match.group("PAGE");
    but this syntax enables me to retrieve only the first
    item.

    There's no desription about this function :
    String[] group(String);

    Any idea ?

    Thanks

    LudoO

     
    • Sergey A. Samokhodkin

      Your question is very common.
      There currently is no way to get the intermediate
      matches, you get only the last one. But in your example you even wouldn't need it, just remove the last quantifier and iterate through the matches using while(find()){...}.
      As for groups() it just returns the contents of all groups of a pattern.

       

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.