-2

Suppose I hvae a match pattern in Ruby regular expression:

VALID_ID = /^[-a-z0-9_.]+$/i

I think it matchs all strings that with characters -, _, 0-9, 'a-z', 'A-Z'. But, I feel confused about the last character . here. What does it mean? Can you provide some examples to explain it?

dj199008
  • 1,739
  • 3
  • 18
  • 27

2 Answers2

2

It matches the char ., the . inside [] is just the dot char, doesn't have a special meaning.

xdazz
  • 158,678
  • 38
  • 247
  • 274
1

If you use the dot(.) outside the [] then it means any character except \n. But if you place this dot(.) inside the [](also known as character-class), then it means only to match the dot(.)

For example:

/[.]/ will match with .

and /./ will match with any characters excepts \n

Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85