Sorry, if this is a lame question, I am quite new to Java development and regex patterns.
Basically I have a long string which has multiple occurrences of substrings like InstanceId: i-1234XYAadsadd, and I want to extract out the i-1234XYAadsadd part in an ArrayList using regex. Please help with the correct regular expression here.
//instanceResultString is the actual string containing occurences of pattern
List<String> instanceIdList = new ArrayList<String>();
Matcher matcher = Pattern.compile("InstanceId:[.]*,").matcher(instanceResultString);
while(matcher.find())
instanceIdList.add(matcher.group());
"InstanceId:\\s*(\\S+),"and access.group(1)InstanceId:, I want to exclude thoseMatcher matcher = Pattern.compile("InstanceId:\\s*(\\S+),").matcher(instanceResultString); while(matcher.find()) instanceIdList.add(matcher.group(1));