If a regex match is found assign it to a variable
Do not set the materialCode to another string. I am not sure, but NA might also be a valid choice for Material=&lt;value&gt;. Instead, just set it to null.

As for the pattern itself, instead of searching for [^,] (anything except ,), you should look for only the valid values. Based on the given examples, I'd assume that only alphanumericals are accepted. If there is a limit on the length, then you should specify that as well.

Since, you are only looking for values assigned to Material property; no need to store the word Material as a matched-group result.

For eg.

Material=(?&lt;value&gt;[A-Z\d]{6})