Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
URL-php中的正则表达式_Php_Regex_Codeigniter - Fatal编程技术网

URL-php中的正则表达式

URL-php中的正则表达式,php,regex,codeigniter,Php,Regex,Codeigniter,我有以下代码来决定使用codeigniter的默认控制器 if ($_SERVER['HTTP_HOST']=="5409.gs.mycoolurl.org") { $route['default_controller'] = 'new-site/newsite'; } else { $route['default_controller'] = ''; } 问题是在5409.gs.中,5409将是随机的,但总是4位数长。如何允许任何4位数字和.gs进入此if语句?我试过: [

我有以下代码来决定使用codeigniter的默认控制器

if ($_SERVER['HTTP_HOST']=="5409.gs.mycoolurl.org") {

   $route['default_controller'] = 'new-site/newsite'; 
}
else {

   $route['default_controller'] = '';
}
问题是在
5409.gs.
中,
5409
将是随机的,但总是4位数长。如何允许任何4位数字和.gs进入此if语句?我试过:

[0-9].gs.mycoull.org
但总是得到事情的
方面

试试这个:

\d{4}.gs

\d代表数字

{4} 是4的范围

试试这个:

\d{4}.gs

\d代表数字

{4} 是4的范围

试试这个:

\d{4}.gs

\d代表数字

{4} 是4的范围

试试这个:

\d{4}.gs

\d代表数字

{4} 是4的范围

解释

\d{4} match a digit [0-9]
Quantifier: Exactly 4 times
\. matches the character . literally
gs matches the characters gs literally (case sensitive)
解释

\d{4} match a digit [0-9]
Quantifier: Exactly 4 times
\. matches the character . literally
gs matches the characters gs literally (case sensitive)
解释

\d{4} match a digit [0-9]
Quantifier: Exactly 4 times
\. matches the character . literally
gs matches the characters gs literally (case sensitive)
解释

\d{4} match a digit [0-9]
Quantifier: Exactly 4 times
\. matches the character . literally
gs matches the characters gs literally (case sensitive)


我最终还是站在事情的另一边(你应该避开圆点。请更新答案。因为它并没有解决问题。我最终还是站在
其他
一边。:(你应该避开圆点。请更新答案。因为它没有解决问题。我仍然站在
其他
一边。:)(你应该避开圆点。请更新答案。因为它没有解决问题。我仍然会在
的另一边结束。:(你应该避开圆点。请更新答案。因为它没有解决问题。
在正则表达式中的意思是“匹配任何东西(如果
s
修饰符未设置,则换行除外)”基本上,你需要将它转义为
\.
或将它放入字符类
[.]
。如果你已经知道
[0-9]
将匹配一个数字,那么只需添加一个量词即可。想想
+
{1,4}
{4}
等。
在regex中的意思是“匹配任何东西”(如果
s
修饰符未设置,则换行除外)”。基本上,您需要将其转义为
\.
或将其放入字符类
[.]
。如果您得到
[0-9]
将匹配一个数字,则只需添加一个量词即可。请考虑
+
{1,4}
{4}
等.
在正则表达式中的意思是“匹配任何内容(如果未设置
s
修饰符,则不匹配换行符)”。基本上,您需要对其进行转义
\.
或将其放入字符类
[.]
。如果您有
[0-9]
将匹配一个数字,然后只需添加一个量词即可。想想
+
{1,4}
{4}
等。
在regex中的意思是“匹配任何东西(如果
s
修饰符未设置,则新行除外)”。基本上,您需要将其转义
\。
或将其放入字符类
[。]
。如果你知道
[0-9]
将匹配一个数字,那么只需添加一个量词即可。想想
+
{1,4}
{4}
等…谢谢谢谢谢谢!我将在4分钟内接受此答案。谢谢谢谢谢谢!我将在4分钟内接受此答案。谢谢谢谢谢谢!我将在4分钟内接受此答案。谢谢谢谢谢谢谢谢!我将在4分钟内接受此答案。