/ nf\w* \h* = \h* \d+ /x # ^ don't make the = optional # ^^^ not arbitrary characters, just allow word characters / nf\w+ \h* = \h* \{ [^}]+ \}/ # ^^^^ don't allow a closing bracket inside the brackets