Javascript:
const re = /(Replace this )(\w+)( with name)/
var i = 1
const res = baseArray.filter(m => (/[a-z]/.exec(m.name))).map(m => {
return { "id" : i++, "content" :
m.content.replace(re, (match, p1, p2, p3, offset, string) => {
return p1 + m.name + p3
})
}
})
Java:
static final Pattern re = Pattern.compile("(Replace this )(\\w+)( with name)");
Map<String,String> transform(Map<String,String> m, final int i) {
Matcher mm = re.matcher(m.get("content"));
if (mm.matches()) {
MatchResult res = mm.toMatchResult();
m.put("content", res.group(1) + m.get("name") + res.group(3));
m.put("id", String.valueOf(i));
}
return m;
}
public void test() {
Pattern re = Pattern.compile("\\d+");
Stream<Map<String,String>> s = baseArray.stream().filter(m -> !re.matcher(m.get("name")).matches())
.map(m -> transform(m, id++));
}