我需要修剪这个字符串 - > http://hokuspokus/ixdebude/ix我完全需要这部分字符串 / ixdebude / ix
我有2个表达式来解决我的问题。
我的第一个正则表达式 - >
/(.*)\/(.*)(\/)(.*)\/*/g
返回Array [5]组。
我的第二个正则表达式 - >
/(\/............)$(.*?)$/g
返回 / ixdebude / ix
你们有人可以给我另一个正则表达式,没有千点的更好吗?
答案 0 :(得分:4)
答案 1 :(得分:3)
你可以试试这个
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"