I recommend that the first example be changed to use struct{} as well. The &quot;strings&quot; are still present in the struct footprint if you leave them there: <a href="http:&#x2F;&#x2F;play.golang.org&#x2F;p&#x2F;ZG1ULgzSwZ" rel="nofollow">http:&#x2F;&#x2F;play.golang.org&#x2F;p&#x2F;ZG1ULgzSwZ</a> And people luuuuuv to pick up the one example where you did something a bit wrong and copy paste like mad....<p>I&#x27;d really rather see something that generates marshaling code based on a regex or something, though. This loads an awful lot of meaning onto things that most code assumes doesn&#x27;t have meaning, like struct field order. It looks really clever in isolation but if you start playing multiple tricks like this in one code base they&#x27;ll start conflicting.<p>For example, note how you now can&#x27;t use encoding&#x2F;json on these objects as currently written. Now, that&#x27;s fixable... well... it&#x27;s <i>probably</i> fixable. AFAIK the struct tagging system isn&#x27;t actually specified, so, for instance, if you try to put a tag<p><pre><code>    regex:&quot;[^\&quot;]+&quot;,json:&quot;quotefree&quot;
</code></pre>
there&#x27;s no guarantee how anything will parse that. Should that backslash be there to get the &quot;character class of everything but double-quote&quot;? Will the regex code get the backslash? Will encoding&#x2F;json see a field &#x27;regex:&quot;[^\&quot;&#x27; and a field &#x27;]+&quot;,json:&quot;quotefree&quot;&#x27; and then fail because there&#x27;s only a field named &#x27;]+&quot;,json&#x27; and not one named &#x27;json&#x27;? Will you encounter one of those situations where the backslash is simultaneously required and not required? Beats me. Plus I don&#x27;t guarantee stability on whatever the answer is between versions, nor do I guarantee it if you reverse the order of the two things, nor do I guarantee it if you try to add a third struct tag.<p>I would suggest taking this code and converting it into a function<p><pre><code>    UnmarshalRegex(*regexp.Regexp, val interface{}) error
</code></pre>
with no use of struct tags, because you get 80-125% of the value, while dodging all the previous problems. I&#x27;d go ahead and say the user of the code is responsible for proper grouping, just describe how it needs to be, and check it at runtime. Especially if you use named capture groups, further removing issues of order.