user3615191
user3615191

Reputation: 21

Regular Expression Explanation [\w-\.]

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"?

Upvotes: 0

Views: 496

Answers (2)

xdazz
xdazz

Reputation: 160853

Hyphen here is just the hyphen character.

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

Upvotes: 1

pavel
pavel

Reputation: 27092

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

Upvotes: 0

Related Questions