Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Grouping getting lost on Java regex with repetition

  •  08-02-2007, 12:27 PM

    Grouping getting lost on Java regex with repetition

    I need to break the following string into seperate 8 seperate groups

     "key:val:key:val:key:val:key:val"

    I really want to avoid using this ugly regex

    ([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)

    So i've tried using a passive group and a quantifier

    (?:([^:]*):){1,6}([^\s])+
     

    The problem is that its fine on the Jakarta regex implementation but when its run using the Java implementation I lose the groups. Is there a way of doing this which will work in both cases?

    Help would be greatly appreciated! Smile

    Filed under: ,
View Complete Thread