使用 regsub 捕获查询字符串左侧的值
capture value to the left of querystring using regsub
这是一个示例 URL:
https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30
我想要的只是:
/productimages/1679/T716AP1_lg
我当前的代码是:
regsub(req.url, "^/(.*)\.(.*)$", "")
在我上面的示例中有多个查询字符串参数 link 之前效果很好,& 似乎给我带来了问题。
尝试捕获 non-dots/questions:
regsub(req.url, "^http://.*?/([^?.]+).*$", "")
描述
^https:\/\/[^\/]+\/([^.]*)\.jpg
此表达式将执行以下操作:
- 从给定的 link 中找到子页面和文件名,假设文件名是 jpg
例子
现场演示
https://regex101.com/r/nZ7eX7/1
示例文本
https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30
样本匹配
productimages/1679/T716AP1_lg
说明
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
https: 'https:'
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
[^\/]+ any character except: '\/' (1 or more
times (matching the most amount possible))
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
( group and capture to :
----------------------------------------------------------------------
[^.]* any character except: '.' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of
----------------------------------------------------------------------
\.jpg '.jpg'
----------------------------------------------------------------------
这是一个示例 URL:
https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30
我想要的只是:
/productimages/1679/T716AP1_lg
我当前的代码是:
regsub(req.url, "^/(.*)\.(.*)$", "")
在我上面的示例中有多个查询字符串参数 link 之前效果很好,& 似乎给我带来了问题。
尝试捕获 non-dots/questions:
regsub(req.url, "^http://.*?/([^?.]+).*$", "")
描述
^https:\/\/[^\/]+\/([^.]*)\.jpg
此表达式将执行以下操作:
- 从给定的 link 中找到子页面和文件名,假设文件名是 jpg
例子
现场演示
https://regex101.com/r/nZ7eX7/1
示例文本
https://mydomainname.net/productimages/1679/T716AP1_lg.jpg?w=125&h=125&tstamp=05/19/2016%2015:08:30
样本匹配
productimages/1679/T716AP1_lg
说明
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
https: 'https:'
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
[^\/]+ any character except: '\/' (1 or more
times (matching the most amount possible))
----------------------------------------------------------------------
\/ '/'
----------------------------------------------------------------------
( group and capture to :
----------------------------------------------------------------------
[^.]* any character except: '.' (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of
----------------------------------------------------------------------
\.jpg '.jpg'
----------------------------------------------------------------------