小编Raj*_*ooq的帖子

如何使用http.ListenAndServe中的下一个可用端口

我写了一个简单的Web服务器来监听端口8080.但我不想使用硬编码的端口号.我想要的是我的服务器监听任何可用的端口.我想知道我的Web服务器正在侦听的端口号.

我的代码如下:

package main

import (
    "net/http"
)

func main() {       
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)

}
Run Code Online (Sandbox Code Playgroud)

port webserver http go

20
推荐指数
2
解决办法
8784
查看次数

正则表达式跳过某些特定字符

我试图清理字符串,使其没有任何标点或数字,它必须只有az和AZ.例如,给定String是:

"coMPuter scien_tist-s are,,,  the  rock__stars of tomorrow_ <cool>  ????"
Run Code Online (Sandbox Code Playgroud)

所需的输出是:

['computer', 'scientists', 'are', 'the', 'rockstars', 'of', 'tomorrow']
Run Code Online (Sandbox Code Playgroud)

我的解决方案是

re.findall(r"([A-Za-z]+)" ,string)
Run Code Online (Sandbox Code Playgroud)

我的输出是

['coMPuter', 'scien', 'tist', 's', 'are', 'the', 'rock', 'stars', 'of', 'tomorrow', 'cool']
Run Code Online (Sandbox Code Playgroud)

python regex string python-2.7

4
推荐指数
1
解决办法
825
查看次数

标签 统计

go ×1

http ×1

port ×1

python ×1

python-2.7 ×1

regex ×1

string ×1

webserver ×1