grep optional character
# You can use append \? to a capture group to make something optional:
grep -nri "^\s*\(public\|private\|protected\)\s*\(static\)\?\s*\(sub\|function\)" formName.frm
#In this case, the preceding group, which contains the string "static", is optional (i.e. may occur 0 or 1 times).