0

https://rubular.com/r/I5qur9Mm1NjWmB

Hello, I am curious about a particular regex which is matching ? character.

Can you link some documentation or provide explanation of why this is matching?

Full regex:

[\ -\/\[-\`\:-\@\{-\~]

Shortened down to:

[:-\\]

Seems to be designed to match some special characters. I had some trouble Googling and searching SO for documentation on this.

c821j
  • 11
  • 1

2 Answers2

5

A hyphen between two characters within square brackets specifies a character range. In this case, the range of : (ASCII index 58) through \ (ASCII index 92) includes those two characters, plus ;, <, =, >, ?, @, [, and all capital letters.

Full reference: https://www.ascii.cl/htmlcodes.htm

CAustin
  • 4,525
  • 13
  • 25
2

The shortened statement matches an ascii range from ; (58) to \ (92). ? is ascii character 63, so it's within that range. Take a look at the ascii table here: https://www.ascii-code.com

Garrett Motzner
  • 3,021
  • 1
  • 13
  • 30