A $regexp() irregularity


#1

Briefly,

$regexp(1a-filename,'^[^ -]+([ -])',$1) ~ $regexp(1a-filename,'^[^ -]+([ -])',$strchr( -,$1)) ~ $regexp(1a-filename,'^[^ -]+([ -])',$strchr( -,-))

emits

-filename ~ 0filename ~ 2filename

because

$regexp(1a-filename,'^[^ -]+([ -])',$strchr( -$1,$1))

emits

3filename

The same is true of $strstr(). Several things puzzle me. Why wasn't the placeholder $1 expanded? Why don't I have to escape the dash, which is the RE special character used in ranges like [a-z], as - in a RE? For that matter, how is it that the RE escape character \ itself doesn't have to be escaped as \\ in a RE? That is,

$regexp(1a-filename,'^[^ -]+([ -])',$strstr( -,))

emits

2filename

instead throwing an error for lack of a closing parenthesis.