I would like to write a very general regexp.
我想写一个非常通用的正则表达式。
It's for:
这是为了:
/something/anything/example
Something, anything and example could be any words. But not it should exclude:
什么,任何东西和例子可以是任何单词。但不应该排除:
/something/anything
Or:
要么:
/something
I know it's basic, but I couldn't find anything for that so far on Google. Thank you!! Tomi
我知道这是基本的,但到目前为止我在Google上找不到任何相关内容。谢谢!!托米
3 个解决方案
#1
1
A very basic regex would be
一个非常基本的正则表达式
^(\/[^\/\n]+){3}$
Example : http://regex101.com/r/eF1xF7/1
示例:http://regex101.com/r/eF1xF7/1
#2
0
In python, for something like "/something" it'd be more-like
在python中,对于像“/ something”这样的东西,它更像是
import re
def fn(x):
return re.findall(r'/[a-zA-Z]+',x)
#3
0
Here's one way using JavaScript:
这是使用JavaScript的一种方式:
var URL = "/something/hello/more"
var re = /\/[^/]+\/*/; // match a "/" then any characters except another "/"
// then another "/" if there if it exists
alert(URL.match(re));
#1
1
A very basic regex would be
一个非常基本的正则表达式
^(\/[^\/\n]+){3}$
Example : http://regex101.com/r/eF1xF7/1
示例:http://regex101.com/r/eF1xF7/1
#2
0
In python, for something like "/something" it'd be more-like
在python中,对于像“/ something”这样的东西,它更像是
import re
def fn(x):
return re.findall(r'/[a-zA-Z]+',x)
#3
0
Here's one way using JavaScript:
这是使用JavaScript的一种方式:
var URL = "/something/hello/more"
var re = /\/[^/]+\/*/; // match a "/" then any characters except another "/"
// then another "/" if there if it exists
alert(URL.match(re));