-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,629
  • 2
  • 15
  • 24

2 Answers2

2

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

xdazz
  • 154,648
  • 35
  • 237
  • 264
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
  • 36,940
  • 12
  • 73
  • 83