Get value of string between two tags
<p>I am fairly new regex but I am trying to learn it. I'm not doing anything complicated; I have some XML:</p>

<pre><code>&lt;root&gt;
   &lt;friendlyName&gt;Hello, I'm friendly&lt;/friendlyName&gt;
   &lt;URL&gt;http://localhost&lt;/URL&gt;
&lt;/root&gt;
</code></pre>

<p>I am trying to get the value of friendlyName but it doesn't appear to be working. I've used an online regex tester from <code>https://regex101.com/</code> which seems to match against what I'm expecting. However, when I try it in Java I get back <code>N/A</code>, <code>N/A</code> being what I return if the string was not found. </p>

<p>Below is my code: </p>

<pre><code>public String getXMLTagValue(String tagName)
    {
        Pattern pattern = Pattern.compile("&lt;" + tagName + "&gt;(.*?)&lt;/" + tagName + "&gt;/s");
        Matcher matcher = pattern.matcher(xmlString);
        while (matcher.find())
        {
            return matcher.group();
        }
        return "N/A";
    }
</code></pre>

<p>I'm expecting the above code to return <code>Hello, I'm friendly</code> but instead I get <code>N/A</code>. </p>