Let's say I have the following String:
name1=gil;name2=orit;
I want to find all matches of name=value
and make sure that the whole string matches the pattern.
So I did the following:
Ensure that the whole pattern matches what I want.
Pattern p = Pattern.compile("^((\\w+)=(\\w+);)*$"); Matcher m = p.matcher(line); if (!m.matches()) { return false; }
Iterate over the pattern
name=value
Pattern p = Pattern.compile("(\\w+)=(\\w+);"); Matcher m = p.matcher(line); while (m.find()) { map.put(m.group(1), m.group(2)); }
Is there some way to do this with one regex?