lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/27/90)
In article <VIXIE.90Jun23004854@volition.pa.dec.com> vixie@decwrl.dec.com (Paul A Vixie) writes:
: [vixie:vax] perl
: /[\+\dx]/;
: /[\+\-\dx]/;
: /[\+\-\dx]/: invalid [] range in regexp at - line 2.
: [vixie:vax]
:
: Why can't I use \- in a character class to get a literal "-" ??
Because people typically do it the Unix Way and put the - in front or back.
I could make it work with backslash, and it might even be reasonable, just
to maintain the principle of least surprise. On the other hand, backslash-itis
is something I try to avoid when possible. Which is why I went with the
egrep notion of (|){} as metacharacters rather than \(\|\)\{\}, since the
metacharacters actually occur rather more frequently than the literal
counterparts.
Larry
vixie@decwrl.dec.com (Paul A Vixie) (06/28/90)
>> I could make it work with backslash, and it might even be reasonable, just >> to maintain the principle of least surprise. On the other hand, >> backslash-itis is something I try to avoid when possible. Which is why I >> went with the egrep notion of (|){} as metacharacters rather than >> \(\|\)\{\}, since the metacharacters actually occur rather more frequently >> than the literal counterparts. Yes, but since you went out of your way to make sure that most \W meta- characters meant their literal selves when backslashed (I refer you to: This makes it sim- ple to quote a string that you want to use for a pattern but that you are afraid might contain metacharacters. Simply quote all the non-alphanumeric characters: $pattern =~ s/(\W)/\\$1/g; ), it seems intuitively neccessary that for ALL \W metacharacters to mean their literal selves when backslashed. I know that's what *I* expected :-). Paul -- Paul Vixie DEC Western Research Lab <vixie@wrl.dec.com> Palo Alto, California ...!decwrl!vixie
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/29/90)
In article <VIXIE.90Jun27164620@volition.pa.dec.com> vixie@decwrl.dec.com (Paul A Vixie) writes:
: Yes, but since you went out of your way to make sure that most \W meta-
: characters meant their literal selves when backslashed (I refer you to:
:
: This makes it sim-
: ple to quote a string that you want to use for a pattern but
: that you are afraid might contain metacharacters. Simply
: quote all the non-alphanumeric characters:
:
: $pattern =~ s/(\W)/\\$1/g;
:
: ), it seems intuitively neccessary that for ALL \W metacharacters to
: mean their literal selves when backslashed. I know that's what *I*
: expected :-).
Ok, you can say /[a\-z]/ now and get a, - and z.
Well, I can say it, anyway. It'll be in the next patch.
Larry