0

What does this RegExp mean please?

[\w-\.]

I know the \w stands for word characters and could alternatively be written as:

[A-Za-z0-9_]

I know the \. means that the point will be treated as an ordinary character.

The only thing I don't really know is the hyphen character. Is this used as a Range Operator here or just the hyphen character in e.g. "fine-tune"?

user3615191
  • 11
  • 1
  • 5

2 Answers2

1

Hyphen here is just the hyphen character.

Hyphen is treated as a range operator only when it is between two other characters.

xdazz
  • 149,740
  • 33
  • 229
  • 258
0

Hyphen is normal character here, so it works as [a-zA-z0-9_-\.] (number, letters, and these three characters: -_.).

pavel
  • 24,015
  • 8
  • 38
  • 57
  • Be careful, in `[a-zA-z0-9_-.]` the `-` *would* be interpreted as a range - and cause an error since `_` ascii value is greater than `.`. I'm guessing you meant `[a-zA-z0-9_.-]` ? – Robin Jul 01 '14 at 07:43