If you're happy with your current regex and just want to have the the $regml return something: put the respective part of the regex inside round brackets to create your back reference, e.g.: /^([\+]?[iRmN]+)$/ for the whole string.