正则表达式查找斜杠之间的字符串模式

Regex to find a pattern of string between slashes

我正在寻找为此构建正则表达式的正确方法:

我有这些网站,我需要删除 string 斜杠之间的任何内容。 使用 https://regexr.com/

我得到了这个结果。有人可以帮助我吗?

http://example.com/string/anotherThings
http://example.com/string/anotherThings
http://example.com/string_string/anotherThings

  • 如果url中有多个斜线,你想取最短的部分还是整个部分,像这样: https://test.com/page/number/1,你到底想要哪一个?
  • 如果是page/number,正则表达式应该是(?<=\/)[\w_\]+(?=\/)
  • 如果是pagenumber,试试(?<=\/)[\w_]+(?=\/)