The syntax error you're receiving is because the regular expression needs to be surrounded by quotes, either single or double. Otherwise, the vertical bar character is treated as a Unix pipe, which redirects the Standard Out from the command preceding the pipe to the Standard In of the command following the pipe.
Once that is solved, however, you'll then receive another error: Invalid preceding regular expression
$ find ./ -regextype posix-extended -regex "^.*\/[a-z]\d\%|&|#|-[a-z][a-z]\@|:|?|;\d[A-Z]"
find: failed to compile regular expression '^.*\/[a-z]\d\%|&|#|-[a-z][a-z]\@|:|?|;\d[A-Z]': Invalid preceding regular expression
This is because you're not escaping the right characters. Out of those listed in the assignment, only the Question Mark needs to be escaped.
With regards to these special characters, the regular expression can be defined with either Character Classes (open and close brackets) or Alternates (with the vertical bar character). If Alternates, then they should be grouped within parenthesis. So you have two options:
$ find ./ -regextype posix-extended -regex "^.*\/[a-z]\d(%|&|#|-)[a-z][a-z](@|:|\?|;)\d[A-Z]"
Or the following. But note that because this version is using the Character Class brackets, you do not need to escape the Question Mark.
$ find ./ -regextype posix-extended -regex "^.*\/[a-z]\d[%&#-][a-z][a-z][@:?;]\d[A-Z]"
But this probably won't work as intended, because of \d
. With POSIX Regular Expressions, you need to use either [0-9]
or [[:digit:]]
. Otherwise, \d
will be interpreted as a literal "d". So that makes the final command as follows:
$ find ./ -regextype posix-extended -regex "^.*\/[a-z][0-9][%&#-][a-z][a-z][@:?;][0-9][A-Z]"
Or...
$ find ./ -regextype posix-extended -regex "^.*\/[a-z][[:digit:]][%&#-][a-z][a-z][@:?;][[:digit:]][A-Z]"
As a side note, to find two lower case letters, you can use [a-z]{2}
instead of [a-z][a-z]
.
And if I may, as a final piece of advice...
When creating regular expressions or problem solving in general, it's best to start small and build from there. Change one thing at a time, ensuring that it's functioning as intended, and then when it breaks, figure out why it broke and adjust accordingly.