Was this helpful?
-
The dash ( - ) has two meanings.
1. It is the subtraction operator as in "variable - number" where both the variable and the number are numeric. The subtraction operator is used to subtract numeric variables or constants in an expression. The value of the variable on the right is subtracted from the value of the variable on the left.
Example
counter = counter - 1; # Count down
2. The dash ( - ) is also a metacharacter that is used in regular expressions. It is used to create a range in a character class. It will match any of the characters from the character on the left of the dash to the character on the right of the dash, inclusive.
Example
/[A-Z]/
will match any string with upper case letters
/[^[0-9]+$/
will match any line that consists of only digits. For information on how they participated in this regular expression, see ^ [ ] + and $.
For a definition of a character class, see [ and ] .
Last modified date: 02/01/2024