简体   繁体   English

正则表达式在斜线之间找到字符串模式

[英]Regex to find a pattern of string between slashes

I'm looking for the right way to build the regex for this: 我正在为此寻找正则表达式的正确方法:

I have these sites and I need cut the word string or whatever have between slashes. 我有这些站点,我需要剪切字符串或斜线之间的任何内容 Using the https://regexr.com/ 使用https://regexr.com/

I had this result. 我有这个结果。 Someone can help me? 有人可以帮我吗?

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

例

  • If there are multiple slashes in the url, do you wish to retrive the shortest part or the whole part, like this: https://test.com/page/number/1 , which one do you actually want? 如果网址中有多个斜杠,您是否希望检索最短的部分或整个部分,例如: https://test.com/page/number/1 : https://test.com/page/number/1 ,实际上是您想要的?
  • If it's page/number , the regex should be (?<=\\/)[\\w_\\]+(?=\\/) 如果是page/number ,则正则表达式应为(?<=\\/)[\\w_\\]+(?=\\/)
  • If it's page , number , try (?<=\\/)[\\w_]+(?=\\/) 如果是pagenumber ,请尝试(?<=\\/)[\\w_]+(?=\\/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM