0

正規表現の使用は初めてです。次のようなすべてのサブドメインを受け入れる必要があります。

something.mysite.com
something2.mysite.com
anotherthing.mysite.com

次のようなことをしたい場合、どのような正規表現をそこに置くことができますか:

rack_env['SERVER_NAME'].match <regex>
4

4 に答える 4

3

ここでは正規表現を使用しないでください。行く方法は次のとおりです。

rack_env['SERVER_NAME'].end_with?(".mysite.com")
于 2013-02-13T15:08:14.553 に答える
0

の線に沿った何かが\.mysite\.com$機能するはずです。http://rubular.comは、正規表現をテストするための優れたリソースです。

于 2013-02-13T15:01:12.500 に答える
0
[a-zA-Z0-9]+\.[a-z]+\.com

something.mysite.com //ok
something2.mysite.com //ok
anotherthing.mysite.com //ok
something2mysite.com //not ok
anotherthing.mysitecom //not ok

しかし、それは危険です。

于 2013-02-13T15:02:47.440 に答える
0

変更されているのがサブドメインだけの場合は、次を使用できます。

/\w+\.mysite\.com/
于 2013-02-13T15:03:31.337 に答える