The issue that the error message addresses is not the single quotes but the parentheses. Unquoted parentheses are special to the shell, and their meaning depends on their placement on the command line. The unquoted single quotes and the input redirection operator < will also be an issue, so it's better that you quote the whole of the regular expression to prevent the shell from interpreting it as shell syntax:
grep -P -o "(?<=')[a-zA-Z_0-9]+(?=':)" eg.txt
Since your expression contains single quotes and a single-quoted string can't contain single quotes, I'm using double quotes to quote the entire expression.
If your input is a well-formed JSON document (using double quoted keys and values), then it would be easier to get the top-level keys from it using a JSON parser, such as jq:
$ cat file
{
"simple_example": 345,
"to_demonstrate": 232,
"regex": "is not easy to use"
}
$ jq -r 'keys[]' file
regex
simple_example
to_demonstrate
This extracts the top-level keys into an array (with keys) and then expands that array into a set (with []), which is then outputted decoded (i.e. as "raw" strings rather as encoded JSON strings, due to -r).