Java replace multiple substrings within a string with regex
<p>I have generated an UML file from a model.xml with UML2 generator.</p>

<p>Now I want to replace the generated ids created in xmi:id="generated id".</p>

<p>Below is a snippet of the generated UML code.</p>

<pre><code>&lt;packagedElement xmi:type="uml:Package" xmi:id="_lAAK0A34Eeap1Y_jd5mZDA" name="java"&gt;
  &lt;packagedElement xmi:type="uml:Package" xmi:id="_lAAK0Q34Eeap1Y_jd5mZDA" name="lang"&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK0g34Eeap1Y_jd5mZDA" name="String"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK0w34Eeap1Y_jd5mZDA" name="Boolean"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1A34Eeap1Y_jd5mZDA" name="Byte"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1Q34Eeap1Y_jd5mZDA" name="Character"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1g34Eeap1Y_jd5mZDA" name="Double"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK1w34Eeap1Y_jd5mZDA" name="Float"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK2A34Eeap1Y_jd5mZDA" name="Integer"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK2Q34Eeap1Y_jd5mZDA" name="Long"/&gt;
    &lt;packagedElement xmi:type="uml:DataType" xmi:id="_lAAK2g34Eeap1Y_jd5mZDA" name="Short"/&gt;
  &lt;/packagedElement&gt;
&lt;/packagedElement&gt;
</code></pre>

<p>I have tried to use regex to remove the IDs. First I read the file and convert it to a string then I find an pattern with Matcher and try to replace it. One problem is that the gernerated ID's are similar but not the same and i don't know how to tackle this. I guess this doesn't work because it only takes the first? </p>

<pre><code>Path path = profileFile.toPath();
Charset charset = StandardCharsets.UTF_8;
String replaceString = "";
String content = new String(Files.readAllBytes(path), charset);
Pattern pattern = Pattern.compile("xmi:id=\"([A-Za-z0-9_]*)\"");
Matcher matcher = pattern.matcher(content);
if (matcher.find())
{
  replaceString = matcher.group(0);
  Pattern p = Pattern.compile("\"([^\"]*)\"");
  Matcher m = p.matcher(replaceString);
  if (m.find())
  {
    System.out.println("is this the real life:    " + m.group(1));
    replaceString = m.group(1);
  }
}
// content = content.replaceAll("xmi:id=\"([A-Za-z0-9_]*)\"", "xmi:id=\"\"");
content = content.replaceAll(replaceString, "");
Files.write(path, content.getBytes(charset));
</code></pre>

<p>Any idea is appreciated, you can just nudge me in the right direction. My brain is a bit blurry right now.</p>