Question

In most, if not all implementations of regular expressions, the \w metacharacter matches all alphanumeric characters plus the underscore.

Historically speaking, why was the underscore character included in this character class? And why not include dashes too?

Was it helpful?

Solution

Because underscores are second-nature for identifiers in almost all computer languages that matter. Dashes are not; they're typically used as an operator for subtraction, and are specifically excluded from identifiers.

Licensed under: CC-BY-SA with attribution
scroll top