0

This is a part of my URL

-pony-byggesættet-har-ikke-bare-vundet-vores-hænder-men-ogsa-vores-hjerter-

I was surprised by the result. I had to include a few special symbols, and found out that

([a-zA-Z0-9.-ÆØÅæøå]+)$

doesn't catch the URL whereas

([ÆØÅæøåa-zA-Z0-9.-]+)$

catches the URL. Could anyone kindly explain why is that?

Thank you in advance.

Jiri
  • 115
  • 8

1 Answers1

2

That is because:

.-Æ

looks for:

a single character in the range between . (index 46) and Æ (index 198)

and your second regex adds all desired characters including - into the list.

Same bavior happens with:

a-z

That looks for:

a single character in the range between a (index 97) and z (index 122) (case sensitive)

You can find out more on Regex101.

zipa
  • 27,316
  • 6
  • 40
  • 58
  • 1
    To expand on this... in your second expression the hyphen is being treated as a character to match because there is no range terminator following it whereas in the first expression it is treated as a range separator rather than a literal character. – NeilMacMullen May 04 '18 at 13:11
  • Thank you guys for the replies. I appreciate your effort. – Jiri May 05 '18 at 09:17