I currently have the following regex to parse data. And an array of “exclusions”
$userNameArray = (userName1, user Name2, User Name 3);
$re = '/^(?<timeMined>[0-9]{2}:[0-9]{2}:[0-9]{2}) # timeMined
\s+
(?<userName>[\w\s]+) # user name
\s+(?:has\s+looted)\s+ # garbage text between name and amount
(?<amount>\d+) # amount
\s+x\s+ # multiplication symbol
(?<item>.*?)\s*$ # item name (to end of line)
/xmu';
preg_match_all($re, $sample, $matches, PREG_SET_ORDER);
foreach ($matches as $value){
code
}
My code currently has an if statement that if $value['userName'] is in $userNameArray to execute part of a code, and if not, do a different part. However this would be significantly easier if I could just parse the bad users out in the regex.
While you could use a negative lookahead as in
that would encode significant application logic into a regular expression. Most likely, your current solution is easier to understand, more readable, and easier to change.