Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Regex 正则表达式在Golang HandleFunc函数中不起作用_Regex_Go - Fatal编程技术网

Regex 正则表达式在Golang HandleFunc函数中不起作用

Regex 正则表达式在Golang HandleFunc函数中不起作用,regex,go,Regex,Go,我正在尝试根据Go中的模式重定向URL。如果我的URL包含clientApi,则我将其发送到clientApi点func,否则我将其发送到RedirectAPI点func。我的手最需要的功能是 {^?!clientApi.*$}如果我的url类似于 localhost:8081/somerandonurl (sending it to redirectApiPoint func) 但如果url中有一个或多个/,则regex不会将其重定向到redirectApiPoint func 您的正则表

我正在尝试根据Go中的模式重定向URL。如果我的URL包含clientApi,则我将其发送到clientApi点func,否则我将其发送到RedirectAPI点func。我的手最需要的功能是

{^?!clientApi.*$}如果我的url类似于

localhost:8081/somerandonurl  (sending it to redirectApiPoint func)
但如果url中有一个或多个/,则regex不会将其重定向到redirectApiPoint func


您的正则表达式在localhost:8081/somerandonurl上工作,因为第一个/so匹配

您需要像/*$这样的东西,但这将匹配任何/blala/blala/

您可以从这里测试您的正则表达式:

无法用于注册模式以匹配正则表达式。是否考虑了/?此外,您可能不希望每次命中端点时都编译正则表达式—这是一个昂贵的操作。只要它不会改变,就在别处编译它。
localhost:8081/somerandonurl  (sending it to redirectApiPoint func)
localhost:8081/somerandonurl/somethingdifferent    (not sending it to redirectApiPoint. 404 page not found message)